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.
1.4m articles
1.4m replys
5 comments
57.0k users