Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chapter 3 scope clarification (AKA who will gotcha the gotchas?) #49

Open
jordy248 opened this issue Jan 28, 2021 · 0 comments
Open

Chapter 3 scope clarification (AKA who will gotcha the gotchas?) #49

jordy248 opened this issue Jan 28, 2021 · 0 comments

Comments

@jordy248
Copy link

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:

image

Compare this with declaring the variable with let:

image

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant