8 Concepts to Make You Code Truly Pure Functions in JavaScript

As you would do in a functional programming language

Arnold Abraham
Nerd For Tech

--

Image made by the Author with ❤

Pure functions behave identically to mathematical functions and give you diverse benefits. It is considered to be one if it matches two conditions:

  1. Given the same arguments, the function always calculates and returns the same result.
  2. When calculating its result, the function doesn’t cause any observable side effects.

Summing it up to a memorizable sentence:

Pure functions don’t depend on, and don’t modify, anything outside their scope, and do always return the same result for the same input arguments.

You might also be reminded about a software design principle that is really important in the context of pure functions.

A function should do one thing, only one thing, and nothing but that thing.

If a function does more than one thing and has some hidden functionality, you won’t predict the function’s output. Hence makes things harder for you as a developer.

Pure Functions Do This the Best

The major advantage of working with pure functions is their lack of side effects. Calling them means not to worry about…

--

--

Arnold Abraham
Nerd For Tech

JavaScript, TypeScript and C#/.NET Tutorials/News/Best Practices by a German Software Engineer - Fun helps you to learn on the fly --> arnoldcode.com