console.log(a);
let a = 10;
var b = 100;
Output:
script.js:1 Uncaught ReferenceError: Cannot access 'a' before initialization
let a;
console.log(a);
a = 10;
console.log(a);
Output:-
undefined
10
Doubt:- While performing the first console.log(a), a is in temporal dead zone since it hasn't been initialized. So why is it not throwing any error and printing undefined?
Because you have defined the variable but not the content
in the first example the variable is defined after is called so it throw an error
in the second case the variable is defined but it's content doesn't.
So the first console.log print the content undefined