JS #6 :: 구조분해 할당(Destructuring assignment)

해다·2022년 3월 20일
0

JavaScript & TypeScript

목록 보기
5/10
post-thumbnail

🙊 잘못 기재한 부분이 있다면 댓글로 남겨주세요!


💻구조 분해 할당(Destructuring assignment)

배열이나 객체의 속성을 해체하여 그 값을 개별 변수에 담을 수 있게 하는 Javascript의 표현식이다.

let a, b, rest;
[a, b] = [10, 20];

console.log(a); // 10

console.log(b); // 20

[a, b, ...rest] = [10, 20, 30, 40, 50];
console.log(rest);// [30,40,50]
let a, b, rest;
[a, b] = [10, 20];

console.log(a); // 10

console.log(b); // 20

[a, b, ...rest] = [10, 20, 30, 40, 50];
console.log(rest);// [30,40,50]

💡참고

MDN 구조분해할당

profile
잘하는 건 아닌데 포기하진 않을거야

0개의 댓글