Sobes.tech
Middle

Explain what a pure function is.

sobes.tech AI

Answer from AI

A pure function is a function that always returns the same result given the same inputs and has no side effects. This means it does not modify external state, does not depend on external variables, and does not interact with the outside world (for example, it does not change global variables, does not perform input-output operations).

Example in JavaScript:

function add(a, b) {
  return a + b;
}

This function is pure because it always returns the sum of its arguments and does not modify anything outside itself.