What is a Temporal Dead Zone?

Forums JavaScriptWhat is a Temporal Dead Zone?
Staff asked 2 years ago

Answers (1)

Add Answer
Nayan Raval Marked As Accepted
Staff answered 2 years ago

Variables declared with the let and const keywords exhibit Temporal Dead Zone behaviour.

It occurs when we attempt to access a variable before it has been initialized.

The following are some examples of temporal dead zones:

x = 23; // Gives reference error

let x;


function anotherRandomFunc(){
  message = "Hello"; // Throws a reference error

  let message;
}
anotherRandomFunc();

 

Subscribe

Select Categories