getify / You-Dont-Know-JS

A book series on JavaScript. @YDKJS on twitter.
Other
177.97k stars 33.41k forks source link

If statement also creates a scope of its own #1734

Closed sabres207 closed 3 years ago

sabres207 commented 3 years ago

In Scope & Closures book - chapter 2. In the marbles and buckets metaphor, you point out the global, function and for scopes - but if actually also creates a scope of its own.

Thanks for the so far awesome books

getify commented 3 years ago

if (and other statements with blocks) do not always create scopes, only if there's a let / const inside the block.