Temporal Dead Zone
The Temporal Dead Zone (TDZ) is the period between entering a scope where a lexical binding exists and reaching the declaration's initialization. During that period, reading or accessing the binding results in a ReferenceError.
The TDZ is a runtime concept, not merely a parser restriction. This explains why typeof someLetVariable can throw when the variable is in the TDZ.
TDZ in Action
{
// console.log(typeof name); // ReferenceError
let name = 'Suriya';
console.log(typeof name);
}💡 The lexical binding exists when the block begins, but it is uninitialized until the let declaration executes.
Key Takeaways
- TDZ applies to let, const, and class declarations.
- A lexical binding can exist without being initialized.
- TDZ helps prevent accidental use of variables before initialization.
Knowledge Check
Which declaration is subject to the Temporal Dead Zone?