Immutability

Immutability refers to the inability to change the value of a variable after a value has been assigned to it. Purely FP languages include immutable implementations of common data structures. For example, when we add an element to an array, we are mutating the original array. However, if we use an immutable array, and we try to add a new element to it, the original array will not be mutated, and we will add the new item to a copy of it.

In JavaScript and TypeScript, we can use the Immutable.js library to enjoy immutable data structures.

Get Learning TypeScript 2.x - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.