JavaScript Temporal dead zone

Beginner
6 min read
Updated: Nov 2026

Definition and Usage

The temporal dead zone (TDZ) is the time from entering a scope until a let or const finishes initializing. Reading the binding in that window throws ReferenceError.

JavaScript Syntax

JavaScript
try {
  console.log(a);
  let a = 1;
} catch (e) {
  console.log(e.name);
}
Try it Editor

How It Works

  1. Enter scope. a exists but is uninitialized.
  2. Read. Throws ReferenceError.

Examples

Example 1 — After init

Safe to use.

JavaScript
let a = 1;
console.log(a);
Try it Editor

How It Works

  1. Initialization completed.

Example 2 — typeof still throws

Unlike undeclared vars.

JavaScript
try { typeof x; let x = 1; } catch (e) { console.log(e.name); }
Try it Editor

How It Works

  1. TDZ applies to typeof too.

Example 3 — const same rule

Must initialize on the line.

JavaScript
const n = 3;
console.log(n);
Try it Editor

How It Works

  1. const always initializes at declaration.

Frequently Asked Questions

About execution order in a scope—not merely line numbers in the file.
No. var is undefined until assigned.

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful