Home/Tutorials/JavaScript/Destructuring and Spread

0 of 3 saved

JavaScript5 min read

Destructuring and Spread

Read this chapter, write the program on this page, then pass a short check to open the next one.

Unpack and copy cleanly.

Destructuring and Spread

Destructuring pulls fields out of objects/arrays. Spread (...) copies or merges.

  • const { name } = user;
  • const [first, ...rest] = list;
  • const next = { ...user, role: "lead" };
const user = { name: "Ada", role: "dev" };
const { name } = user;
const copy = { ...user, role: "lead" };
console.log(name, copy.role);

After you read this chapter, use Write (when available) and Quiz on this page to lock it in.