Sitemap
vignesh

vignesh

Temporal Dead Zone in JavaScript

2 min readAug 11, 2025

--

JavaScript is a flexible language that offers many features to make coding easier and to avoid common mistakes. One of these features, introduced in ES6, is the Temporal Dead Zone (TDZ). This idea is important for understanding how variables declared with let and const work. In this article, we will explore the TDZ in detail, look at its causes, and provide practical examples.

Key Characteristics of the TDZ:

  1. Variables declared with let or const are hoisted but not initialized.
  2. Accessing these variables before they are initialized causes a runtime error.
  3. The TDZ prevents potential bugs that could arise from accessing them too early.

Get vignesh’s stories in your inbox

Join Medium for free to get updates from this writer.

The first thing to understand is that all three, let, const, and var, are hoisted. However, let and const behave differently from var. Variables declared with var are stored in the global object, so they can be accessed before initialization, but they will have an undefined value. In contrast, let and const are stored in a separate area called the “script” or “temporal dead zone.” They are hoisted and declared before the code execution starts, but they are not initialized. If you try to access them before initialization, you will get a ReferenceError.

Press enter or click to view image in full size

In the above image, you can clearly see that let and const exist outside the global object. This causes a reference error because they are declared but not initialized. For example, in the case of let a and const c, the time between when a variable is declared and when it is initialized is known as the Temporal Dead Zone.

Why Does the TDZ Exist?

The TDZ was introduced to safer coding practices. Before ES6, variables declared with var were hoisted and initialized with undefined, often leading to unexpected behaviors.

HOISTING ?

In JavaScript ,Hoisting is the process where certain declaration hoisted to the top of their scope during the compilation phase-before the code is actually executed.

--

--