LearnFrenzy
Sign in Take a free test

Arrays · Predict the Output · Question 11

concat with nested arrays Answer, explanation & discussion

  • Output
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 11 Back to Exercise

What does the following JavaScript code print (console output, as in Node.js)?

main.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!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links