What is the output of the following code? “`js const obj = { a: 1, b: 2 }; const { a, …rest } = obj; console.log(rest); “`

JavaScript Professional Medium

JavaScript Professional — Medium

What is the output of the following code? “`js const obj = { a: 1, b: 2 }; const { a, …rest } = obj; console.log(rest); “`

Key points

  • Destructuring in JavaScript allows for extracting values from objects
  • The rest operator (...) is used to gather remaining properties into a new object
  • The extracted 'a' property is assigned to a variable, leaving the 'b' property in the rest object

Ready to go further?

Related questions