JesseJ
0
Q:

destructuring assignment

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
4
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;
7
({ 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}
6

New to Communities?

Join the community