The Temporal Dead Zone (TDZ) is a specific time between whenever we declare any variable using
let keyword and initializing declared variable a value, the time span between these two events known to be as temporal dead zone, whenever we try to use variable in between temporal dead zone state, we get
Reference Error because it will be always unreachable for the particular time being till it gets initialized.
console.log(num); let num = 10;
In memory creation phase of the
Why TDZ not with
Because of hoisting we can access any variable created using
var even before it gets declared, and we get an special value as
undefined because it attached to global object.
It doesn't mean variable created with
let are not hoisted but in the case of
const the initialization must be in the same line while declaring the variable.