Question 14
Back to Exercise
The code below runs without an error, but its result is wrong. Which statement correctly identifies the bug?
const tags = ["js", "css"];
const newTag = "react";
const updated = [...tags, ...newTag];
console.log(updated.length, updated.join(","));
- A Spreading a string adds its characters – add the string itself: [...tags, newTag] Correct
- B Arrays cannot contain strings
- C join adds the commas
- D tags must be spread twice
Correct Answer: Option A
Strings are iterable, so ...newTag expands to "r", "e", "a", "c", "t". Only spread values that are collections you want to unpack.
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!