Destructuring Arrays and Objects
Destructuring (ES2015) pulls values out of arrays or objects into named variables in a single step.
const [first, second] = ["a", "b", "c"];
const { name, age: years = 18 } = { name: "Nadia" };
// years is 18, because 'age' wasn't present on the object
const { address: { city } } = { address: { city: "Dhaka" } };
Array destructuring matches by position, so [first, second] grabs the first two elements regardless of what they're called. Object destructuring matches by key name, and you can rename while destructuring (age: years) and provide a default (= 18) that applies only when the property is undefined or missing entirely.
Destructuring is heavily used in function parameters — function greet({ name, age }) {...} — to unpack an options object directly into named, self-documenting variables at the call site.