QA
Intermediate LevelJavaScript & TypeScript

What is the Temporal Dead Zone (TDZ) in detail and how does the JS engine handle declarations?

❓ Interview Prompt: Explain the TDZ boundary starting from scope entry up to declaration initialization.

The Temporal Dead Zone (TDZ) is the time window between entering a block scope and the line where a let or const variable is formally declared and initialized.

Execution Engine Mechanics:

1
Creation Phase: When entering a block, the JS engine scans for let/const declarations and allocates memory bindings, but marks them as uninitialized.
2
TDZ Window: Accessing the variable before its declaration line triggers a ReferenceError.
3
Initialization Line: Once the execution reaches the declaration line, the variable exits TDZ and becomes accessible.

Code Implementation Example

javascript
// --- Block Scope Entered (TDZ for 'value' begins!) ---
function demo() {
  // typeof x; // ❌ ReferenceError! (x is in TDZ)
  
  let value = 'Hello'; // --- TDZ for 'value' ends here! ---
  console.log(value); // "Hello" (Accessible!)
}

// Parameter TDZ example
// function calc(a = b, b = 2) {} // ❌ ReferenceError! 'b' evaluated before declaration
💡Scope entry vs initialization line defining the Temporal Dead Zone boundary.
🎯 Interview Key Takeaway

Variables declared with let and const exist in the Temporal Dead Zone from block entry until their explicit initialization line.

More JavaScript & TypeScript Interview Questions

Beginner LevelJavaScript & TypeScript

What are the differences between var, let, and const in JavaScript?

Beginner LevelJavaScript & TypeScript

What are the JavaScript data types and the difference between primitives and objects?

Beginner LevelJavaScript & TypeScript

What is the difference between == (loose equality) and === (strict equality)?