Pure Functions
Pure functions are a key component of Functional Programming. A pure function can be defined as a function that does not have any effect on or make use of any state outside of the function. A function must meet three key criteria to be considered pure:
A function must always return the same output, when given the same inputs.
A function must have no side effects.
A function must have referential transparency.
Same Output Given Same Input
Given a set of input values, a pure function must always return the same value when provided those input values. This sounds much more complicated than it is. Simply put, the output of a pure function cannot change unless the input values are changed. This means that a function's internal code cannot depend on any program state outside of the function. A pure function cannot use any variable from outside the function to make calculations or code path decisions. An example of this is shown in the following snippet:
const state = { prop1: 5 }...