LearnFrenzy
Sign in Take a free test

Destructuring · Predict the Output · Question 17

Rest inside a nested array Answer, explanation & discussion

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

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

main.js
const [[a, ...b], c] = [[1, 2, 3], 4];
console.log(a, b, c);
  • A 1 [ 2, 3 ] 4 Correct
  • B 1 [ 2, 3, 4 ] undefined
  • C [ 1, 2, 3 ] 4 undefined
  • D 1 2 4
Correct Answer: Option A

The inner pattern applies to the first item [1, 2, 3]; its rest collects 2 and 3. c is the second outer item.

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