Question 14
Back to Exercise
What does the following JavaScript code print (console output, as in Node.js)?
const grid = new Array(2).fill([]);
grid[0].push(1);
console.log(grid);
- A [ [ 1 ], [] ]
- B [ [ 1 ], [ 1 ] ] Correct
- C [ 1, [] ]
- D [ [], [] ]
Correct Answer: Option B
Both slots point to the same inner array, so the push shows up in both rows.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!