The Temporal Dead Zone in JavaScript
The temporal dead zone is the span between entering a scope and executing a let/const declaration — touching the variable there throws ReferenceError (Cannot access before initialization) instead of yielding undefined. It's a deliberate safety feature: var's silent undefined masked ordering bugs, while the TDZ converts them into loud, located failures.
The zone covers the whole block from its top, which surprises people inside loops and switch cases (each case shares one block scope — declare in braces). typeof isn't exempt either: typeof x in the TDZ throws just like any other access.
Declared but untouchable
{ console.log(x); let x = 1; } throws — the binding exists from block entry but refuses access until its line.
Safer than undefined
var's pre-line undefined silently computed wrong answers; TDZ errors point at the exact ordering mistake.
typeof throws too
The safe-check operator offers no shelter — typeof tdzVar before its line throws identically.
Order declarations first
Top-of-block lets plus no use-before-declare (lint rule) keep code permanently outside the zone.
try { console.log(value);} catch (e) { console.log("caught:", e instanceof ReferenceError);}let value = 10;Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Practice what you learned
Re-implement each visualized algorithm in JavaScript yourself — building beats watching.