Skip to content

QuizNot attempted

TDZ

Which line throws?
console.log(typeof undeclaredThing); // 1
console.log(typeof later); // 2
let later = 1;
1–4 to choose, Enter to submit
Show answer & explanation

Correct answer:

  • Line 2 (ReferenceError: TDZ)
  • typeof on a name that was never declared is safe and gives 'undefined', but later IS declared: let bindings are hoisted and uninitialized until the declaration runs (the TDZ), so even typeof later throws ReferenceError.
  • Not line 1: undeclared names are the one case typeof protects.
  • Not both: line 1 never throws.
  • Not neither: TDZ access throws even through typeof.