Mutable한 객체는 생성된 이후에 상태가 변경될 수 있는 객체이고, Immutable한 객체는 생성된 이후에 상태가 변경되지 않는 객체를 말한다. 자바스크립트에서 Object와 Array를 제외한 모든 타입은 Immutable한 타입이다.
let immutableString = 'Hello';
// In the above code, a new object with string value is created.
immutableString = immutableString + 'World';
// We are now appending "World" to the existing value.
immutableString에 string 값을 더하면, 아래와 같은 이벤트들이 발생한다.
Immutable 객체는 내용이 변하지 않는 객체를 말한다. 객체는 다양한 이유로 불변적일 수 있는데, 예시로 아래와 같은 경우가 있다.
Mutable은 바뀔 수 있는 변수 타입을 말한다. Javascript에서는 object와 array만 Mutable한 타입이고, 원시 타입은 Immutable하다.