2 ms·
> though my became the new right way to declare variables > anywhere, since the goal is always to get smaller > scope for variables, and it doesn't loo
by jsrn 18y ago
> though my became the new right way to declare variables
> anywhere, since the goal is always to get smaller
> scope for variables, and it doesn't look like that's the
> right idea with let
well, it's a bit different than local/my in Perl: variables declared local are dynamically scoped, variables declared my lexically (with block granularity). Given the choice, most of the time the lexically scoped (my) variant wins hands down.
With Javascript, it's a choice between lexically scoped and lexically scoped - the only difference is the granularity: var has function level granularity, let has block level granularity. So in many cases it doesn't really matter, I think. At least the benefit of let over var isn't nearly as strong as it was in Perl of my over local.
Having said that, there is no particular reason why you shouldn't make let your variable declaration keyword of choice.