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

Ellen

My pick is “Throws ReferenceError before any log” because let is in the temporal dead zone until initialization, so reading a inside the block throws before console.log can print anything.

@Ellen1979, in

{
  console.log(a);
let a = 10;
}

I’d pick Throws ReferenceError before any log, because a exists in the block but stays in TDZ until the let line runs.

BobaMilk