What is the temporal dead zone?

JavaScript Functions & Scope Intermediate 2–3 Yrs3–5 Yrs Conceptual 1 min read

Quick Answer

The temporal dead zone (TDZ) is the region from the start of a block until a let/const declaration is reached. The variable is hoisted (the scope knows about it) but uninitialised, so referencing it in the TDZ throws ReferenceError: Cannot access 'x' before initialization — unlike var, which would just be undefined.

The temporal dead zone is the gap between entering a block and reaching a let or const declaration. The variable is technically hoisted — the block knows it exists — but it's not initialised, so if you touch it in that gap you get a ReferenceError, not undefined like you would with var. Even typeof throws in there. It's actually a good thing — it stops you accidentally using a variable before it's been given a value.

  • Even typeof x throws in the TDZ (for var it returns "undefined").
  • The TDZ is why const/let feel safer — you can't accidentally use a variable before it's set up.
  • It's per-block: { console.log(y); let y = 1; } throws; the outer scope's y is not consulted.