Skip to content
Discussion options

You must be logged in to vote

What are mutable vs immutable objects?

In programming, mutable and immutable objects describe whether an object’s state can change after it’s created.

Mutable objects

A mutable object can be modified in place—its internal data/state changes.
Example (Python): list
You can append/remove/update elements without creating a new list.
Example (JavaScript): Map, Set, plain objects ({})
You can add/remove entries or properties

Immutable objects

An immutable object cannot be modified after creation. Any “change” produces a new object instead.
Example (Python): tuple, str, int, frozenset
Example (JavaScript): strings ("abc") are immutable; operations like concatenation create a new string.

Why i…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by sudoUgando
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants