Question 1
Back to Exercise
What does the following JavaScript code print (console output, as in Node.js)?
const a = [1, 2];
console.log(a.push(3, 4), a.pop(), a);
- A 4 4 [ 1, 2, 3 ] Correct
- B [ 1, 2, 3, 4 ] 4 [ 1, 2, 3 ]
- C 4 [ 1, 2, 3 ] [ 1, 2, 3 ]
- D 2 4 [ 1, 2, 3 ]
Correct Answer: Option A
push returns the new length (4); pop returns the removed element (4). The arguments are evaluated left to right before printing.
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!