A temporal dead zone (TDZ) is the area of a block where a variable is inaccessible until the moment the computer completely initializes it with a value. A block is a pair of braces ( {…} ) used to group multiple statements.
The temporal Dead Zone is the period of time during which the let and const declarations cannot be accessed.
The Temporal Dead Zone starts when the code execution enters the block which contains the let or const declaration and continues until the declaration has been executed.
Temporal Dead Zone Basically work on let and const not work on var
let and const does not hoist they are held in a scope called TDZ
The temporal Dead Zone is the period of time during which the let and const declarations cannot be accessed.
The temporal Dead Zone starts when the code execution enters the block which contains the let or const declaration and continues until the declaration has been executed.
In our code example above, Temporal Dead Zone starts after the opening parenthesis of the printAge function and continues until after the declaration of the age variable.
Consider the following code example that illustrates an interesting point about the Temporal Dead Zone.
The final salient difference between let / const and var is that if you access var before it’s declared, it is undefined. But if you do the same for let and const, they throw a ReferenceError.
Therefore, a let (or const) variable’s TDZ ends when JavaScript fully initializes it with the value specified during its declaration.
However, a var variable’s TDZ ends immediately after its hoisting—not when the variable gets fully initialized with the value specified during its declaration.