JavaScript Interview Question #9

What is the Temporal Dead Zone (TDZ)?

JavaScript Fundamentals, Types, Scope & Functions Junior Beginner

Quick Interview Answer

The Temporal Dead Zone is the period between entering a block scope and executing the declaration of a let, const, or class binding. During this period, the binding exists but cannot be accessed.

Detailed Explanation

The Temporal Dead Zone is the period between entering a block scope and executing the declaration of a let, const, or class binding. During this period, the binding exists but cannot be accessed.

Attempting to read the variable before its declaration is evaluated throws a ReferenceError. The TDZ helps detect incorrect access patterns that could otherwise silently produce undefined values.

Code Example

{
    // console.log(total); // ReferenceError: TDZ
    const total = 100;
    console.log(total); // 100
}