es6 assign multiple variables from object code example

Example 1: destructuring objects

({ 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}

Example 2: destructured object

let renseignement = ['voleur' , '10' , 'spécialité'] ;


let [classe , force, magie] = renseignement ;

console.log(classe) ;
console.log(force) ;
console.log(magie) ;

Example 3: object destructuring

let a, b, rest;
[a, b] = [10, 20];

console.log(a);
// expected output: 10

console.log(b);
// expected output: 20

[a, b, ...rest] = [10, 20, 30, 40, 50];

console.log(rest);
// expected output: Array [30,40,50]