JavaScript의 변수와 기본값
변수 이름을 변경하면서 동시에 기본값을 설정할 수도 있습니다:
let obj = {
month: 12,
day: 31,
};
let {year:y = 2025, month, day} = obj;
console.log(y); // 2025 출력
console.log(month); // 1 출력
console.log(day); // 31 출력
다음 코드에서 객체의 일부는 해당 변수에 기록됩니다:
let options = {
width: 400,
height: 500,
};
let c;
if (options.c !== undefined) {
c = options.color;
} else {
c = 'black';
}
let w = options.width;
let h = options.height;
배운 이론에 따라 이 코드를 구조 분해 할당을 사용하여 다시 작성하세요.