Question 11
Back to Exercise
What does the following JavaScript code print (console output, as in Node.js)?
console.log([1].concat(2, [3, [4]]));
- A [ 1, 2, 3, 4 ]
- B [ 1, 2, [ 3, [ 4 ] ] ]
- C [ 1, 2, 3, [ 4 ] ] Correct
- D [ [ 1 ], 2, 3, 4 ]
Correct Answer: Option C
concat spreads array arguments one level deep; the inner [4] stays an array.
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!