block-level scope
for (var i = 0; i < 10; i++) {
/* ... */
}
console.log(i); // what will this output?
should be undefined
for other languages, but 10
for JS.
variable hoisting
Variable i
remains in scope even after the for loop has completed, retaining its last value after exiting the loop.
let
let
The support for block-level scopes is available for the new let
keyword.
Last updated
Was this helpful?