[Javascript] Immutable & mutable

tia·2021년 10월 20일
0

코드스테이츠

목록 보기
4/7

1. immutable(변경불가능성)

  • 객체가 생선된 이후 그 상태를 변경 불가
  • 원시 타입(primitiave values): Boolean, String, Number, Null, undefined, Symbol
  • 변수에 할당할 때 완전히 새로운 값이 만들어져서 재할당이 됨

2. mutable

  • immutable type을 제외한 모든 값은 객체(Object) 타입
  • 변할 수 있는 값
  • 새로운 값을 만드는 것이 아니라 직접 변경 가능

3. String Method

immutable

  • String.slice()
  • String.split()

문자열 메서드는 전부 immutable

4. Array Method

immutable

  • Array.join()
  • Array.slice()
    begin부터 end 전까지의 복사본을 새로운 배열 객체로 반환
    원본 배열은 수정되지 않음

mutable

  • Array.unshift()
  • Array.shift()
  • Array.push()
  • Array.pop()
  • Array.splice()
    배열의 기존 요소를 삭제/교체하거나 새로운 요소를 추가해 배열의 내용을 변경

참조 블로그
https://sustainable-dev.tistory.com/156
https://velog.io/@mnmm/js-immutable

0개의 댓글