What is Temporal Dead Zone in JavaScript?

What is Temporal Dead Zone in JavaScript?

ยท

1 min read

Play this article

Temporal Dead Zone is a term that describes the position where variables are unreachable;

Here,

  • Temporal means, temporary
  • Dead means, not in a working state
  • Zone means, the area where data is stored

The variables let and const exists in Temporal Dead Zone

TL;DR Temporal Dead Zone(TDZ) ends as soon as the respective variable is called.

/* 
    Temporal Dead Zone for the name variable
*/
const name = "SnowBit" // Haha, TDZ just ended 
console.log(name)

Why was Temporal Dead Zone(TDZ) created?

//Temporal Dead Zone for the name variable
//Temporal Dead Zone for the name variable
//Temporal Dead Zone for the name variable
console.log(name) // Huh, I am in Temporal Dead Zone, let's get out of it
//Temporal Dead Zone for the name variable
//Temporal Dead Zone for the name variable
const name = "SnowBit" // Haha, TDZ just ended

As you can see, the name variable is declared in TDZ and will show error tdz error.png


Thank you for reading, have a nice day!

Have a nice day.png

ย