LearnFrenzy
Sign in Take a free test

Destructuring · Predict the Output · Question 6

Object rest Answer, explanation & discussion

  • Output
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 6 Back to Exercise

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

main.js
const { a, ...rest } = { a: 1, b: 2, c: 3 };
console.log(a, rest, Object.keys(rest).length);
  • A 1 { b: 2, c: 3 } 2 Correct
  • B 1 [ 2, 3 ] 2
  • C 1 { a: 1, b: 2, c: 3 } 3
  • D { a: 1 } { b: 2, c: 3 } 2
Correct Answer: Option A

The rest element collects every property that was not destructured into a new object.

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