Currying in JavaScript is a technique that turns a function taking several arguments into a chain of functions that each take one argument. Instead of calling add(1, 2, 3), you call add(1)(2)(3). The main payoff is partial application: you fix some arguments early and get back a smaller, reusable function. This guide builds on closures and pure functions, because currying works by remembering earlier arguments in a closure.
JavaScript has no built-in curry, but you can write one in a few lines.
A normal function takes all its arguments at once. A curried function takes them one at a time and returns a new function until it has everything it needs.
Each call returns a function that closes over the arguments received so far. Only the last call computes the result. The number of arguments a function expects is called its arity, and currying converts an n-ary function into n unary functions.
The two ideas are related but not identical.
| Idea | What it does | Example |
|---|---|---|
| Currying | Converts f(a, b, c) into f(a)(b)(c) | addCurried(1)(2)(3) |
| Partial application | Fixes some arguments and returns a function for the rest | add.bind(null, 1) |
A curried function makes partial application natural, because calling it with fewer arguments already returns a function waiting for the rest.
You can also do partial application without currying by using Function.prototype.bind:
The arrow-function style above has to be written by hand for every function. A reusable curry helper reads the function's length property, which is the number of declared parameters, and keeps collecting arguments until it has enough.
This version accepts any grouping of arguments. When the collected arguments reach fn.length, it calls the original function. Libraries such as Lodash (_.curry) and Ramda (R.curry) provide the same idea with extra features.
fn.length does not count rest parameters or parameters with default values. A function declared as function f(a, b = 2, ...rest) has a length of 1, so curry would call it after the first argument. For such functions, pass the arity explicitly in your own helper or avoid currying them.
Currying fits well with map and filter, which pass exactly one value to your callback.
Without currying you would write n => isGreaterThan(n, 5) each time. The curried form reads like a sentence and the callbacks are named and reusable.
Currying helps when:
map, filter and pipelinescompose or pipeIt is a poor fit when:
f(a)(b)(c) can surprise readersChoose argument order carefully. Put the arguments that change least first (such as configuration) and the data last, so partial application produces useful functions. This is why functions like map(fn)(list) take the data last in functional libraries.
No. Currying always turns a function into a chain of single-argument functions. Partial application fixes any number of arguments at once and returns a function for the remainder. Currying makes partial application convenient.
No. You write one yourself, as shown above, or use a library such as Lodash or Ramda. The language only gives you the building blocks: closures, arrow functions and bind.
Each returned function needs to remember the arguments from earlier calls. A closure keeps those values alive without any global variable.
No. It is a way to organise code, not an optimisation. Each step creates a function, so it adds a small cost rather than removing one.
Currying converts a multi-argument function into a sequence of one-argument functions, each remembering earlier arguments through a closure. Use it to create specialised, reusable functions and to feed map and filter. A generic curry helper based on fn.length works for fixed-arity functions, but it breaks with default or rest parameters. Order your parameters so the data comes last.