JavaScript · Scope · Mid-Level · Debugging
What is the Temporal Dead Zone (TDZ), and how does it show up in interviews?
Short Interview Answer
TDZ is the period from entering a scope until a `let`/`const`/class binding is initialized; accessing it throws ReferenceError.
Detailed Explanation
When a block is entered, `let`/`const` bindings exist in the environment but are uninitialized. Any read or write before the declaration statement runs throws ReferenceError — that window is the TDZ. It also affects default parameters that reference later parameters, and `typeof` on an undeclared `let` (unlike undeclared globals, `typeof` does not safely return `'undefined'` for TDZ bindings). TDZ exists to catch use-before-define bugs that `var`'s silent `undefined` hid.
Example
function f(a = b, b = 2) {
return a + b;
}
f(); // ReferenceError: Cannot access 'b' before initializationInterview Tip
Use the default-parameter example — it separates people who memorized TDZ from people who understand it.
Common Mistake
Thinking TDZ means the variable doesn't exist at all; the binding exists but is uninitialized.