Objects and Destructuring
Objects hold named properties. Destructuring, spread and shorthand make code shorter and keep types.
Example
const user = { name: "Ada", age: 21, city: "Lagos" };
const { name, ...rest } = user;
const copy = { ...user, age: 22 };
console.log(name, rest, copy.age);
const [first, second = 0] = [10];
console.log(first, second);Result
Ada {
age: 21,
city: "Lagos",
} 22
10 0Exercise
Copy with spread.
const c = { user };
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.