currying
Currying is the technique of rewriting a function that takes several arguments as a chain of functions that each take one argument, so a call such as add(2, 3) becomes add(2)(3).
Each call in the chain returns a new function that remembers the arguments received so far, and only the last call runs the original logic. A curried function is a higher-order function, and every function it returns is a closure. Nested arrow functions write it in one line: (a) => (b) => a + b.
The name honors the logician Haskell Curry, although other logicians described the idea before him. JavaScript has no built-in curry operation. Utility libraries such as Lodash and Ramda provide curry() helpers instead.
Currying is often confused with partial application, which fixes some arguments in one step and returns a function that takes the rest. The .bind() method of Function does partial application. In everyday code, currying turns general functions into preconfigured callbacks for methods such as .filter().
Example
In this example, a dashboard filters its orders by status. A curried hasStatus() takes the status first and returns the test that .filter() calls for each order:
> const hasStatus = (status) => (order) => order.status === status;
undefined
> const orders = [
… { id: 1, status: "shipped" },
… { id: 2, status: "pending" },
… { id: 3, status: "shipped" },
… ];
undefined
> orders.filter(hasStatus("shipped")).map((order) => order.id)
[ 1, 3 ]
> hasStatus("pending")(orders[1])
true
The call hasStatus("shipped") returns a function that remembers "shipped", so .filter() receives a one-argument test. The last line supplies both arguments in a row, one call at a time.
A generic curry() helper can convert an existing function. It collects arguments until it has as many as the function’s .length, the number of parameters the function expects, then calls it:
> function curry(fn) {
… return function curried(...args) {
… if (args.length >= fn.length) {
… return fn(...args);
… }
… return (...rest) => curried(...args, ...rest);
… };
… }
undefined
> const formatPrice = (currency, decimals, amount) =>
… `${currency}${amount.toFixed(decimals)}`;
undefined
> const toDollars = curry(formatPrice)("$", 2);
undefined
> toDollars(5)
'$5.00'
> curry(formatPrice)("EUR ")(0)(19.5)
'EUR 20'
Step through either call chain to watch curried() collect arguments until it has fn.length of them:
Like most library helpers, this version accepts several arguments per call as well as one. It relies on .length, which doesn’t count rest parameters or any parameter from the first one with a default value onward. A function with either kind of parameter gets called too early.
Related Resources
Course
JavaScript Scope, Closures, and Functional Patterns for Pythonistas
Port a bouldering gym's front-desk script to JavaScript, and learn where names live and when they exist, how closures keep state, and how to work with rest parameters, callbacks, and timers.
For additional information on related topics, take a look at the following resources:
Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.
By Leodanis Pozo Ramos • Updated Nov. 22, 2026