You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The "Function-level scope" section of Chapter 3 (second edition, accessed on O'Reilly) mentions the following:
With block-level scope, our i would exist only within the context of the for loop, for example, so any attempts to read the value of i or change i outside of the loop would fail. This is nice because you could establish other variables from within your loop and know that they wouldn’t conflict with variables that exist elsewhere.
Because we used var to declare the i variable in the for loop, i gets attached to the window (hey! that's the next section! 😄), so we actually could access it outside of the for block:
Compare this with declaring the variable with let:
This is horrible JS minutia that's absolutely outside the scope of this section's objectives, but it's caused me grief in the past, so I figured I'd point it out.
The text was updated successfully, but these errors were encountered:
The "Function-level scope" section of Chapter 3 (second edition, accessed on O'Reilly) mentions the following:
Because we used var to declare the
i
variable in the for loop,i
gets attached to the window (hey! that's the next section! 😄), so we actually could access it outside of the for block:Compare this with declaring the variable with let:
This is horrible JS minutia that's absolutely outside the scope of this section's objectives, but it's caused me grief in the past, so I figured I'd point it out.
The text was updated successfully, but these errors were encountered: