Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Revisions

2 of 3
updated first paragraph with let and const, added past tense to initial statement

JavaScript didn't have block scope until var and let were introduced, just function scope. Since the initialization of i is within one function, that variable is accessible anywhere else in that same function.

From MDN:

Important: JavaScript does not have block scope. Variables introduced with a block are scoped to the containing function or script, and the effects of setting them persist beyond the block itself. In other words, block statements do not introduce a scope. Although "standalone" blocks are valid syntax, you do not want to use standalone blocks in JavaScript, because they don't do what you think they do, if you think they do anything like such blocks in C or Java.

user2718994

AltStyle によって変換されたページ (->オリジナル) /