Destructuring assignment is special syntax introduced in ES6, for neatly assigning values taken directly from an object. const user = { name: 'John Doe', age: 34 }; const { name, age } = user; // name = 'John Doe', age = 34
const book = { title: 'Ego is the Enemy', author: 'Ryan Holiday', publisher: { name: 'Penguin', type: 'private' } }; const {title: bookName = 'Ego', author, name: {publisher: { name }} = book, type: {publisher: { type }} = book } = book;
({ a, b } = { a: 10, b: 20 }); console.log(a); // 10 console.log(b); // 20 // Stage 4(finished) proposal ({a, b, ...rest} = {a: 10, b: 20, c: 30, d: 40}); console.log(a); // 10 console.log(b); // 20 console.log(rest); // {c: 30, d: 40}