Extracting Values
Destructuring is a convenient way to extract values from arrays or properties from objects into separate variables.
Key Concept: Instead of accessing values one by one, destructuring lets you "unpack" them all at once!
// The old way - repetitive! let user = { name: 'Alice', age: 25, city: 'NYC' }; let name = user.name; let age = user.age; let city = user.city;
// The new way - clean and concise! let user = { name: 'Alice', age: 25, city: 'NYC' }; let { name, age, city } = user; console.log(name); // 'Alice' console.log(age); // 25 console.log(city); // 'NYC'