Functions & Programming Concepts · Level 2 of 5
Pure Function
A function whose result depends only on its inputs and that has no observable side effects.
Purity makes reasoning and testing easier but does not imply computational simplicity.
Example
A routine returns the sum of its arguments without changing external state.
Listen to the definition and example
Audio transcript
Pure Function. A function whose result depends only on its inputs and that has no observable side effects. Purity makes reasoning and testing easier but does not imply computational simplicity. For example: A routine returns the sum of its arguments without changing external state.
Explore this concept
A useful analogy
A calculator that always gives the same result for the same inputs and leaves the room unchanged.
Why it matters
This helps you distinguish a computation’s contract, inputs, outputs, and behavior.
Technical detail
Referential transparency allows replacing a call by its value without changing observable program behavior.
Common misconception
Returning a value does not make a function pure if it also mutates external state.
Start with
Related concepts
Quick recall question
Try answering before looking back at the definition.