Glossary · Programming

Immutability

Immutability means a value cannot be changed after it is created; instead of modifying it, code produces a new value with the change applied.

Updated October 6, 2026

Immutability is the property of data that cannot be modified once it has been created. To "change" an immutable value, a program creates a new value that includes the change and leaves the original untouched.

Why it matters

Immutable data removes a whole class of bugs in which one part of a program silently alters data that another part is using. It makes code easier to reason about, simplifies caching and undo, and is safe to share between threads without locks, which is why functional languages and libraries such as React and Redux favor it. Strings are immutable in Java, Python and JavaScript. The trade-off is that naive copying can cost time and memory, so efficient immutable structures share unchanged parts between versions.

Example

const site = Object.freeze({ host: "example.com", up: true });
site.up = false;                  // ignored (error in strict mode)

const down = { ...site, up: false };   // new object, original unchanged

Common mistakes

  • Assuming const makes an object immutable; it only prevents reassigning the variable, not changing the contents.
  • Freezing only the top level while nested objects stay mutable.
  • Copying huge structures on every small change.

Get notified when this term updates

Plus occasional practical tips on uptime and monitoring, nothing else. Unsubscribe anytime.

This page is general information written by our editorial team and updated when documentation changes. Servers and providers differ, so test changes safely first. See our editorial policy and disclaimer.