I\'ve heard that accessing let
and const
values before they are initialized can cause a ReferenceError
because of something called the
In case of let and const variables, Basically, Temporal Dead Zone is a zone
"before your variable is declared",
i.e where you can not access the value of these variables, it will throw an error.
ex.
let sum = a + 5; //---------
//some other code // | ------> this is TDZ for variable a
// |
console.log(sum) //---------
let a = 5;
above code gives an error
the same code will not give an error when we use var for variable 'a',
ex.
var sum = a;
console.log(sum) //prints undefined
var a = 5;