Codington
0 of 8 problems solved • 0%

Exercise prompt

Collect the Rest of an Object

Rest in destructuring collects properties that were not extracted.

Example

const user = { name: "Mira", age: 20, city: "Lund" }; const { name, ...details } = user; console.log(details.age, details.city); // Output: // 20 Lund
  • name receives "Mira".
  • ...details collects { age: 20, city: "Lund" }, excluding name.

Rest gathers properties; spread places properties into an object.

Predict the output

A book card separates its title from the remaining details. Predict which keys the details object contains.

const book = { title: "Dune", author: "Frank Herbert", pages: 412 }; const { title, ...details } = book; console.log("Keys:", Object.keys(details).join(","));
What will this code print?