본문 바로가기
JAVASCRIPT

[JAVASCRIPT] 구조 분해 할당, 전개 연산자, 불변성, 얕은 복사 깊은 복사

by mikrw 2023. 1. 25.

구조 분해 할당 (Destructuring assignment)

const user = {
  name: 'kim',
  age: 85,
  email: 'test@gmail.com'
}

const {name, age, email, address='Korea'} = user

 

전개 연산자 (Spread)

const fruits = ['Apple', 'Banana', 'Cherry']
console.log(...fruits)
// Apple Banana Cherry

 

데이터 불변성 (Immutability)

원시 데이터: String, Number, Boolean, undefined, null
참조형 데이터: Object, Array, Function

 

얕은 복사(Shallow copy): 객체를 복사할 때 원래값과 복사된 값이 같은 참조를 가리키고있는 것

깊은 복사(Deep copy): 객체안에 객체가 있을 경우에도 원본과의 참조가 완전히 끊어진 객체