
"var" declarations are hoisted to the nearest function scope, while "let" and "const" are hoisted to the nearest block scope. This is done by the parser, which keeps two scope stacks, one stack for the current var scope and one for the current let/const scope. When the interpreter enters a scope, we walk all of the declarations and insert them into the variable environment. We don't support the temporal dead zone for let/const yet.
21 lines
254 B
JavaScript
21 lines
254 B
JavaScript
try {
|
|
|
|
let i = 1;
|
|
{
|
|
let i = 3;
|
|
assert(i === 3);
|
|
}
|
|
|
|
assert(i === 1);
|
|
|
|
{
|
|
const i = 2;
|
|
assert(i === 2);
|
|
}
|
|
|
|
assert(i === 1);
|
|
|
|
console.log("PASS");
|
|
} catch (e) {
|
|
console.log("FAIL: " + e);
|
|
}
|