Side effects

In the preceding section, we learned that a pure function returns a value that can be computed using only the arguments passed to it. A pure function also avoids mutating its arguments or any other external variable that is not passed to the function as an argument. In FP terminology, it is common to say that a pure function is a function that has no side effects. This means that when we invoke a pure function, we can expect that the function is not going to interfere (via a state mutation) with any other component in our application.

Some programming languages, such as Haskell, can ensure that an application is free of side effects using its type system. TypeScript has fantastic interoperability with JavaScript, but the downside ...

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.