36.1 배열 디스트럭처링 할당

const arr = [1, 2, 3];

const [one, two, three] = arr;

console.log(one, two, three); // 1 2 3
const [x, y] = [1, 2];

const [x, y]; // SyntaxError

const [a, b] = {}; // TypeError
const [a, b] = [1, 2];
console.log(a, b) // 1 2

const [c, d] = [1];
console.log(c, d); // 1 undefined

const [e, f] = [1, 2, 3];
console.log(e, f); // 1 2

const [g, , h] = [1, 2, 3];
console.log(g, h); // 1 3
// 기본값
const [a, b, c = 3] = [1, 2];
console.log(a, b, c); // 1 2 3

// 기본값보다 할당된 값이 우선한다.
const [e, f = 10, g = 3] = [1, 2];
console.log(e, f, g); //  1 2 3
// Rest 요소
const [x, ...y] = [1, 2, 3];
console.log(x, y); // 1 [2, 3]

36.2 객체 디스트럭처링 할당

const user = { firstName: 'Ungmo', lastName: 'Lee' };

const { lastName, firstName } = user;

console.log(firstName, lastName);// Ungmo Lee
const { lastName, firstName } = user;
// 위와 아래는 동치.const { lastName: lastName, firstName: firstName } = user;