I tried the following code
let let_arr = [];
for (let i = 0; i < 4; i++) {
let_arr[i] = () => {
return {
let_i: i
}
};
}
console.log(let_arr);
and I found the block key exists when we use let in for loop.
[ƒ, ƒ, ƒ, ƒ]
0: () => {…}
arguments: (...)
caller: (...)
length: 0
name: ""__proto__: ƒ ()
[[FunctionLocation]]: iif.js:26
[[Scopes]]: Scopes[3]
0: Block {i: 0}
1: Script {let_arr: Array(4), var_arr: Array(4)}
2: Global {window: Window, self: Window, document: document, name: "", location: Location, …}
While when using var
for (var i = 0; i < 4; i++)
block element is missing.
[[Scopes]]: Scopes[2]
0: Script {let_arr: Array(4), var_arr: Array(4)}
1: Global {window: Window, self: Window, document: document, name: "", location: Location, …}