728x90
// 구조 분해 할당 Desturcturing Assignment
// 데이터 뭉치(그룹화)를 쉽게 만들 수 있다.
const fruits = ['apple','banana','kiwi', 'strawberry']
const [first, second, ...others] = fruits
console.log(first) // apple
console.log(others) // ['kiwi', 'strawberry']
const point = [1, 2]
const [x, y, z = 0] = point
function createUpper(){
return ['apple', 'APPLE']
}
const [title, upper] = createUpper()
console.log(title) // apple
const seungbin = {name: 'Seungbin', age: 28, job:'s/w engineer'}
function display({name, age, job}){
console.log('이름', name)
console.log('나이', age)
console.log('직업', job)
}
display(seungbin)
// job이라는 key를 없애고 work로 변경
const {name, age, job: work, pet='dog'} = seungbin
console.log(name)
console.log(age)
console.log(job)
728x90
'기술 면접 정리 > 자바스크립트' 카테고리의 다른 글
프로토타입 (0) | 2022.06.01 |
---|---|
4장 콜백함수 정리 (0) | 2022.05.04 |
이벤트 루프 (0) | 2022.04.15 |
자바스크립트 엔진 (0) | 2022.04.15 |
preventDefault(); 와 stopPropagation(); 차이 (0) | 2022.04.12 |