Hint
let/const are hoisted but not initialized — accessing them before declaration throws
The Temporal Dead Zone is the period between when a let/const variable is hoisted (block start) and when it is initialized (the declaration line). Accessing it in this window throws a ReferenceError.
{
// ← TDZ for 'a' starts here (block start)
console.log(a); // ❌ ReferenceError: Cannot access 'a' before initialization
let a = 5; // ← TDZ ends, a is initialized to 5
console.log(a); // 5
}
// typeof does NOT protect you in TDZ
console.log(typeof undeclared); // "undefined" — safe (never declared)
console.log(typeof a); // ReferenceError if 'a' is in TDZ!
Why TDZ exists: Intentional design to catch bugs where you accidentally use a variable before its meaningful initialization. var silently returns undefined, masking errors.