What is the output of following code?
console.log(a);
let a = 10;
----o----
The output is:
ReferenceError: Cannot access 'a' before initialization
Variables declared using let
are not hoisted. During the parsing step, JavaScript is aware about the variable. But, till line 2, it will keep the variable in Temporal Dead Zone. That means, we cannot use the code before the variable declaration, as mentioned in the error message.