Currying and Functional Programming Patterns in JavaScript

Currying transforms a function that takes multiple arguments into a sequence of functions that each take one — a functional programming pattern that shows up more in everyday JavaScript than most developers realize.

// Regular function
function add(a, b, c) { return a + b + c; }
add(1, 2, 3); // 6

// Curried version
const curriedAdd = a => b => c => a + b + c;
curriedAdd(1)(2)(3); // 6

// The real payoff: partial application
const addFive = curriedAdd(5);
const addFiveAndTwo = addFive(2);
addFiveAndTwo(1); // 8 - reusable, pre-configured function

// A practical example: creating specialized validators
const minLength = min => str => str.length >= min;
const isValidPassword = minLength(8);
isValidPassword('short');    // false
isValidPassword('longenough'); // true

Currying’s real value is composability — curriedAdd(5) returns a reusable, specialized function you can pass around, store, and reuse elsewhere, rather than repeating the same partial arguments at every call site.