OOP & Design Patterns' own domain taught a whole paradigm built around bundling data and behavior into objects. Functional programming is the other major paradigm, built around a much smaller, more specific idea — and nearly every other concept this domain covers is a direct consequence of taking that one idea seriously.
3 min read
# PURE — same input, always same output, touches nothing outside itself
def add(a, b):
return a + b
# NOT PURE — depends on, and changes, something outside its own input/output
total = 0
def add_to_total(x):
global total
total += x
return totalA pure function has two properties, together: given the same arguments, it always returns the same result (no dependency on a database, a global variable, the current time, or anything else outside its own parameters), and it causes no side effects — it doesn't mutate a variable outside its own scope, write to a file, make a network call, or print to the console. add_to_total fails purity on both counts: its result depends on total's current value (not just its own argument), and calling it changes total for every future call too.
A pure function can be tested with nothing but its arguments and an expected return value — no database to mock, no global state to reset between tests, no timing dependency to control for. It can be called from anywhere, any number of times, in any order relative to other calls, with no risk that calling it twice produces a different result than calling it once (a property this curriculum's own Testing & QA domain implicitly relies on every time it recommends testing one unit of logic in isolation). This is exactly why Testing & QA's over-mocking discussion exists: code with hidden dependencies on external state is what forces heavy mocking in the first place — a pure function simply has nothing that needs mocking.
A program with zero side effects couldn't print anything, save anything, or respond to a network request — side effects are how software actually does anything useful in the world. Functional programming doesn't argue for eliminating side effects; it argues for being deliberate about where they live, pushing as much of a program's actual logic into pure functions and concentrating the unavoidable side effects (a database write, an API call) at the edges, rather than scattering them invisibly throughout.
JavaScript's own array methods lesson already used functions like .map() and .filter() without naming what made them distinctive — every one of them is pure by design: calling numbers.map(x => x * 2) returns a new array and never modifies numbers itself. Recognizing that property explicitly, rather than treating it as an incidental detail of those specific methods, is exactly what the rest of this domain builds on.
Check your understanding
A quick comprehension check — not tracked, not graded, just for you.
1. What two properties together define a pure function?
2. Why does a pure function need no mocking to test?
3. Does functional programming argue for eliminating all side effects from a program?
Functional Programming Concepts