Skip to main content

Command Palette

Search for a command to run...

Temporal Dead Zone

Published
•1 min read•View as Markdown
S

Full-Stack Developer with 1.5 years of experience building scalable, secure web applications using React, Node.js, and PostgreSQL. Skilled in REST APIs, backend architecture, authentication (JWT/JWE), and modern frontend tools. Proven ability to enhance system efficiency, SEO, and user experience.

TDZ (Temporal Dead Zone) is the time between when a variable is hoisted and when it’s actually declared in your code - during that time, you can’t use the variable, or you'll get a ReferenceError

Explanation

console.log(a); // ReferenceError (TDZ of `a`)

let a = 5;

{

console.log(y); // ReferenceError (TDZ of `y`, which exists only inside the block)

let y = 7;

}

//

a and y they sit in two different Temporal Dead Zones (TDZs), because they live in two different lexical environments.

Diagram: Lexical Environments + TDZ

Global (Script) Lexical Environment

─────────────────────────────────────────────

| a → <TDZ> (❌ not initialized) | ← Before `let a = 5`

| |

| 🟥 Accessing `a` here → ReferenceError |

| 🟩 After line `let a = 5` → a = 5 |

─────────────────────────────────────────────

↓ Enters Block { … }

Block Lexical Environment

─────────────────────────────────────────────

| y → <TDZ> (❌ not initialized) | ← Exists only *inside* the block

| |

| 🟥 Accessing `y` before `let y = 7` → Error |

| 🟩 After line `let y = 7` → y = 7 |

─────────────────────────────────────────────