JavaScriptMedium
Explain the difference between mutable and immutable objects in JavaScript
By FrontendPro Editorial Team Updated 8/8/2026
#JavaScript
Answer
Mutable objects allow for modification of properties and values after creation, which is the default behavior for most objects.
js
const mutableObject = {
name: "John",
age: 30,
};
// Modify the object
mutableObject.name = "Jane";
// The object has been modified
console.log(mutableObject); // Output: { name: 'Jane', age: 30 }
Immutable objects cannot be directly modified after creation. Their contents cannot be changed without creating an entirely new value.
js
const immutableObject = Object.freeze({
name: "John",
age: 30,
});
// Attempt to modify the object
immutableObject.name = "Jane";
// The object remains unchanged
console.log(immutableObject); // Output: { name: 'John', age: 30 }
The key difference between mutable and immutable objects is modifiability. Immutable objects cannot be modified after they are created, while mutable objects can be.
