20240701 MON . 구조 분해 할당
arr = [1, 2, 3];
let one = arr[0];
let two = arr[1];
let three = arr[2];
// 구조 분해 할당 방법
let [one2, two2, three2] = arr;
console.log(one2, two2, three2);
let arr2 = [1, 2, 3];
// 요소가 3개인데, 구조 분해 할당은 2개로 할 것임.
let [one3, two3] = arr2;
console.log(one3, two3);
arr2 = [1, 2];
let [one4, two4, three4] = arr2;
console.log(one4, two4, three4); //three4 = undefined 로 할당됨.
console.log(" 객체 구조 분해 할당 ");
person = {
name4: "용",
age4: 26,
location4: "Busan",
};
// 객체의 분해 할당의 기준은 객체의 key 를 기준으로 수행됨.
let { name4, age4, location4 } = person;
console.log(name4, age4, location4);
person = {
name4: "용",
age4: 26,
location4: "Busan",
};
// 객체의 분해 할당이 객체의 key 를 기준으로 수행되지 않음. 따라서 모두 Undefined 값으로 할당됨.