Chapter VI · Functions
Pure Functions
A pure function always produces identical output given identical inputs and causes no side effects.
01 How It Works
Think of a math calculator operation: 2 + 2 always returns 4 without altering anything else.
Pure functions do not mutate external state, global variables, or input arguments.
example.js
function add(a, b) {
return a + b; // Pure: depends only on inputs, modifies nothing outside
}
1. Base outputs entirely on input parameters.
2. Avoid modifying external variables or network state.
3. Return new calculated values safely.
02 Practical Example
Here is how you might see this concept applied in real-world code:
practical.js
const increment = age => age + 1;
Key Takeaway
Pure functions guarantee predictable behavior and simplify debugging.