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

Return to Answer

Fixed typo where var was implied to be block scope instead of const
Source Link

JavaScript didn't have block scope until varconst and let were introduced, justvar which is function scopescoped. 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.

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.

JavaScript didn't have block scope until const and let were introduced, justvar which is function scoped. 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.

updated first paragraph with let and const, added past tense to initial statement
Source Link

JavaScript doesn'tdidn'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.

JavaScript doesn't have block scope, 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.

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.

Post Undeleted by Community Bot
Post Deleted by Community Bot
Source Link
user2718994
user2718994

JavaScript doesn't have block scope, 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.

lang-js

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