11 KiB
| title | chunk | source | category | tags | date_saved | instance |
|---|---|---|---|---|---|---|
| Immutable - Glossary | MDN | 1/3 | https://developer.mozilla.org/en-US/docs/Glossary/Immutable | reference | web, html, css, javascript, documentation | 2026-05-05T05:35:02.716246+00:00 | kb-cron |
MDN HTML HTML: Markup language
HTML reference
HTML guides
Markup languages
CSS reference
CSS guides
Layout cookbook
JavaScriptJS JavaScript: Scripting language
JS reference
JS guides
Web APIs Web APIs: Programming interfaces
Web API reference
Web API guides
- Using the Web animation API
- Using the Fetch API
- Working with the History API
- Using the Web speech API
- Using web workers
Technologies
Topics
Learn Learn web development
Frontend developer course
- Getting started modules
- Core modules
- MDN Curriculum
- Check out the video course from Scrimba, our partner
Learn HTML
Learn CSS
Learn JavaScript
Tools Discover our tools
About Get to know MDN better
Immutable
An immutable value is one whose content cannot be changed without creating an entirely new value, in comparison with mutable values. In JavaScript, primitive values are immutable — once a primitive value is created, it cannot be changed, although the variable that holds it may be reassigned another value. By contrast, objects and arrays are mutable by default — their properties and elements can be changed without reassigning a new value. It can be beneficial to use immutable objects for several reasons:
- To improve performance (no planning for the object's future changes)
- To reduce memory use (make object references instead of cloning the whole object)
- Thread-safety (multiple threads can reference the same object without interfering with one other)
- Lower developer mental burden (the object's state won't change and its behavior is always consistent)
Note that you can easily prove mutability: an object is mutable as long as it offers one way to change its properties. On the other hand, immutability is hard to prove if there are no language semantics to secure it — it is a matter of developer contract. For example, Object.freeze() is a language-level method to make an object immutable in JavaScript.
In this article
See also
- Immutable object on Wikipedia
- Related glossary terms: