0Pricing
JavaScript Academy · Lesson

Pure Functions and Side Effects

Write predictable, testable functions.

What Makes a Function Pure

A pure function has two properties: given the same inputs it always returns the same output, and it causes no observable side effects. Pure functions are predictable and easy to test.

function add(a, b) {
  return a + b;
}
console.log(add(2, 3));
console.log(add(2, 3)); // always 5

Deterministic Output

Purity means determinism. The same arguments must always map to the same result, with no dependence on hidden state, time, or randomness.

function double(n) {
  return n * 2;
}
console.log(double(10)); // always 20

All lessons in this course

  1. Pure Functions and Side Effects
  2. Declarative Data Transformation
  3. Avoiding Mutation
  4. Point-Free Style
← Back to JavaScript Academy