puzzle 08 · javascript

What does this log?

const grid = Array(2).fill([]);
grid[0].push("x");
console.log(grid[1].length);
0
1
2
TypeError

why

fill() puts the same array reference in every slot, so both rows are literally the same array. Use Array.from({ length: 2 }, () => []) to build distinct ones.

Today's puzzlea new one every day, and a streak to keep