Skip to content

Pure Function

Medium — good to knowGeneral Dev

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."

Made with passive-aggressive love by manoga.digital. Powered by Claude.