Array Destructuring

// 배열의 값을 변수에 할당
const [a, b] = [1, 2];
console.log(a, b); // 1, 2

// 기본값 설정
const [c = 3, d = 4] = [];
console.log(c, d); // 3, 4

// 나머지 요소를 배열로 받기
const [e, ...rest] = [5, 6, 7];
console.log(e, rest); // 5, [6, 7]

Object Destructuring

// 객체 속성을 변수에 할당
const {x, y} = { x: 10, y: 20 };
console.log(x, y); // 10, 20

// 기본값 및 별칭 사용
const {a = 30, b: newB = 40} = { a: 15 };
console.log(a, newB); // 15, 40

// 중첩 구조 분해
const {m, n: {p, q}} = { 
	m: 50,
	n: { 
		p: 60,
		q: 70
	}
};
console.log(m, p, q); // 50, 60, 70

Destructuring in Function Parameters

// 함수 매개변수에서 객체 디스트럭처링 사용
function display({ name, age }) {
    console.log(name);
    console.log(age);
}

display({ name: 'John', age: 30 }); // John, 30