Pure Function
ELI5 — The Vibe Check
A pure function is the well-behaved kid of programming. Give it the same inputs and it always gives you the exact same output, every time, without touching anything outside. No surprises, no hidden effects, completely predictable.
Real Talk
A pure function always produces the same output for the same inputs and has no side effects. It does not read or write external state. Pure functions are trivially testable, composable, and safe to run concurrently since they are referentially transparent.
Show Me The Code
// Pure — same input always returns same output
const double = (n: number) => n * 2;
// Impure — depends on external state
let multiplier = 2;
const impureDouble = (n: number) => n * multiplier;
When You'll Hear This
"Keep the business logic in pure functions so they're easy to test." / "Refactor that into a pure function — no more hidden dependencies."
Related Terms
Functional Programming
Functional programming is like cooking with strict rules: no shared bowls, no side dishes contaminating each other, and every dish must be exactly reproduc...
Idempotent
Idempotent means you can do the same thing multiple times and get the same result as doing it once.
Return Value
A return value is what a function hands back to you after doing its work. You send a coffee machine beans and water, it returns coffee.
Side Effect
A side effect is when a function secretly does something beyond just giving you an answer — like changing a global variable, writing to a file, or sending...