Immutability

» Glossary » Immutability

An element is considered immutable if it cannot be modified once created. Data changes are encapsulated as operations that take the old element/state and return a new derived element/state.

For example, if the i variable was a mutable element, we’ll do the following:

  int i = 0;
  ...
  i = 1;
  ...
  printf(i);

However, if the i variable was immutable, to get the same result, we’ll do:

  int i = 0;
  ...
  int j = i + 1;
  ...
  printf(j);

Immutability is a core concept in Functional Programming. Its usefulness comes from better code readability, optimisation, and testability.

Lee Byron –Immutable.js author- summarise the fundamental concepts of immutable structures and how they fit in the React ecosystem in the following talk:

See also: