pure function

noun
UK /ˌpjʊə ˈfʌŋkʃən/
US /ˌpjʊr ˈfʌŋkʃən/

A pure function is a helper that always gives the same answer for the same input and never changes anything else.

Adding two numbers is a pure function because 2 plus 3 always makes 5.


OTHER MEANINGS

2. In math, a rule that maps each input to exactly one output with no hidden changes.

The squaring rule is a pure function: every number has one square.

3. A function that does not modify its arguments or global variables.

Our sort helper is a pure function because it returns a new list instead of changing the old one.

4. A function whose result depends only on its parameters.

The tax calculator is a pure function, so testing it is easy.