Case 1:
The below snippet throws a reference error because let variables are hoisted but not initialized.
console.log(x);
let x = 5;
Case 2:
const arr = [1, 2];
arr.length = 10;
console.log(arr[5])
prints undefined instead of throwing a reference error despite being uninitialized. Why?
As we increase the length of the arr object, empty slots get created. Note that these empty slots do not mean they are initialized as undefined. they are uninitialized as well.
My question is why doesn’t it throw an error in the second case?