Shorthand property names

// 일반적인 경우
const obj1 = {
	name: 'Lee',
	age: 25,
};

const name = "Lee";
const age = 25;

// key, value명이 동일한 경우 축약하여 사용가능
const obj2 = {
	name, // name: name,
	age, // age: age,

};

Destructuring Assignment

const obj1 = {
	name: 'Lee',
	age: 25,
};

// 일반적인 경우
const g_name = obj1.name;
const g_age = obj1.age;

// Destructuring Assignment :{}
const {name, age} = obj1;
console.log(name, age);

// 변수명을 변경하여 작성도 가능함
const {name: name2, age: age2} = obj1;
console.log(name2, age2);
const arr1 = ['1','2'];

// 일반적인 경우
const v0 = arr1[0];
const v1 = arr1[1];

// Destructuring Assignment : []
const [d0, d1] = arr1;
console.log(d0, d1);

Spread Syntax (연산자)

const obj1 = {key: '1'};
const obj2 = {key: '2'};
const arr = [obj1, obj2];

// 배열 요소만 그대로 가져옴
const copyArr = [...arr];
const copyArr2 = [...arr, {key : '3'}];
 
// [ { key: '1' }, { key: '2' } ]
console.log(copyArr); 
// [ { key: '1' }, { key: '2' }, { key: '3' } ]
console.log(copyArr2);

// 원본 값이 바뀌면?
obj1.key= 10;

// 모두 영향
// [ { key: 10 }, { key: '2' } ]
console.log(copyArr);

// [ { key: 10 }, { key: '2' }, { key: '3' } ]
console.log(copyArr2);
const obj1 = {key: '1'};
const obj2 = {key2: '2', key3: '3'};

// Object의 Spread Syntax
const obj3 = {...obj1, ...obj2}

// { key: '1', key2: '2', key3: '3' }
console.log(obj3);

const obj4 = {key: '1'};
const obj5 = {key: '2', key: '3'};
const obj6 = {...obj4, ...obj5}

// 덮어쓰기 발생: { key: '3' }
console.log(obj6);

Default Parameters