marijnh / Eloquent-JavaScript

The sources for the Eloquent JavaScript book
https://eloquentjavascript.net
3.01k stars 795 forks source link

Ch 03, Summary section #407

Closed dant00ine closed 6 years ago

dant00ine commented 6 years ago

I found the following sentence in 03_functions Summary confusing.

Bindings declared with var behave differently—they end up in the nearest function scope or the global scope.

To me, this makes it sound like var bindings can 'bleed up' up a level into the parent scope or something. Even though blocks were mentioned a couple sentences back, it was still unclear to me that this sentence implies that: "Bindings declared with var [within blocks that aren't functions] behave differently..."

On the other hand, I find this explanation from the MDN docs for let

This is unlike the var keyword, which defines a variable globally, or locally to an entire function regardless of block scope.

to be much more clear.

marijnh commented 6 years ago

To me, this makes it sound like var bindings can 'bleed up' up a level into the parent scope or something.

Isn't that exactly what they do?

dant00ine commented 6 years ago

Oops, what I meant to say was: it makes it sound like they will ‘bleed up’ even through function scopes (not just blocks).

Actually, now that I read it again a day later it makes perfect sense. Sorry for the trouble. Love your book.