Javascript: Mutable & immutable

Narayan Sharma
2 min readMar 11, 2019

Mutable: In simple terms, the mutable data type can be changed once we have created it. That means we can modify the existing variable without assigning the value to another variable. In JavaScript, only array and object are mutable.

Immutable: The Immutable data type can’t be changed once we have created it. That means we can’t modify the existing variable without assigning the value to another variable. The very important thing is value can be reassigned but existing value can’t be changed. All primitive data types are an immutable eg. string, boolean, number, null, undefined and symbol are immutable.

In the above example, variable “name” is immutable data types, When I concat “Sharma” to the variable “name”, The original value of variable “name” doesn’t change its original value. It returns a final result set “Narayan Sharma”.

--

--