Here are two examples:
console.log(x); let x = 4;
throws Reference Error x is not defined;
{ console.log(y); let y = 3; }
throws Reference Error Cannot access 'y' before initialization;
So, my question is: why JS engine interprets these two cases differently? At the creation phase let is uninitialized, and only at execution phase it has value undefined and then assigned to a value.
2.1m questions
2.1m answers
60 comments
57.0k users