Question 13
Back to Exercise
What does the following JavaScript code print (console output, as in Node.js)?
const a = [1, 2, 3];
const r = a.reverse();
r.push(0);
console.log(a);
- A [ 3, 2, 1, 0 ] Correct
- B [ 1, 2, 3 ]
- C [ 3, 2, 1 ]
- D [ 1, 2, 3, 0 ]
Correct Answer: Option A
reverse changes a in place and returns a itself, so pushing to r pushes to a. Use toReversed() for a copy.
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!