Your product could be here, in front of thousands of JavaScript developers. Sponsor this spot →
JavaScript Quiz

What does the rest operator do in object destructuring?

Do you know what will be the output of this code?

JavaScript
const { a, ...rest } = { a: 1, b: 2, c: 3 };
console.log(rest);
Show answer and explanation

The answer is { b: 2, c: 3 }.

...rest gathers every property that wasn’t destructured into a new object. It’s a common way to copy an object without one key.

Take the full quiz Next question →

More Objects questions

  1. Does the spread operator make a deep copy?
  2. When do default parameters apply in JavaScript?
  3. What is the difference between ?? and || in JavaScript?
  4. How does optional chaining short-circuit in JavaScript?
  5. When do destructuring default values apply?

Related topics