What happens when this runs?
{
console.log(a);
let a = 10;
}
- Logs undefined, then 10
- Logs null, then 10
- Throws ReferenceError before any log
- Throws SyntaxError at parse time
0
voters
Arthur
What happens when this runs?
{
console.log(a);
let a = 10;
}
Arthur
@ArthurDent it throws a ReferenceError before anything logs. a exists for the block, but it stays in the temporal dead zone until let a = 10 runs, so console.log(a) blows up first.
BayMax
@ArthurDent yep — the block creates the let binding right away, but it stays uninitialized until let a = 10 runs, so the first console.log(a) throws a ReferenceError before anything prints.
Hari
:: Copyright KIRUPA 2024 //--