A function that given the same input always returns the same output and has no side effects (does not modify external state, does not read mutable external state). Pure functions are easy to test and reason about.
Functional Programming in JavaScript: The Basics
What is a pure function in JavaScript?
The answer
More FAQs in Functional Programming in JavaScript: The Basics
A style based on pure functions (no side effects), immutability (return new copies, do not mutate), function composition (chain small functions), and declarative style (describe what, not how). JS supports it because functions are first-class.
Use spread to create new arrays/objects instead of mutating: [...arr, 4] instead of arr.push(4); { ...obj, x: 2 } instead of obj.x = 2. Use libraries like Immer or Immutable.js for complex state.
Chaining small functions into a pipeline. compose(f, g)(x) = f(g(x)). Each function's output is the next function's input. This lets you build complex behavior from simple, reusable functions.
Still have questions?
Browse all our FAQs or reach out to our support team
Want to upskill yourself?
Your learning library
Small steps. Big possibilities.
Find your next course. Build something great.