JS Quiz: Temporal dead zone edge case

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

Yoshiii

Choosing “Throws ReferenceError before any log” because Accessing a let binding before initialization hits the temporal dead zone, so console.log(a) throws at runtime before printing anything.

Ellen

Yep, that’s the TDZ case—console.log(a) throws a ReferenceError before anything prints.

BayMax