I want to get deep understanding of the for...of loops and destructuring assignment in JS. The following code throw an error on line 3: "ReferenceError: y is not defined", but "y" is defined just before the for loop statement. What's the problem?
let arr = [ ];
let y = 8;
for (let { x = 2, y } of [{ x: 1 }, 2, { y }]) {
arr.push(x, y);
}
console.log(arr);