Question 13
Back to Exercise
The code below runs without an error, but its result is wrong. Which statement correctly identifies the bug?
const todo = ["email", "report"];
const backup = todo;
todo.push("meeting");
console.log("Backup:", backup);
- A push adds to every array
- B const arrays are shared automatically
- C backup = todo copies the reference, so both names show the same array – copy with [...todo] Correct
- D console.log prints the newest array
Correct Answer: Option C
Arrays are objects. const backup = [...todo]; (or todo.slice()) keeps a separate copy with two items.
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!