JavaScript Currying
Quick answer
Currying transforms a multi-argument function into a sequence of single-argument functions. Partial application fixes some arguments while leaving the remaining ones for a later call.
How it works
const add = a => b => a+b is curried; const addTax = calc.bind(null, taxRate) partially applies the first argument of calc. An explicit closure can partially apply non-leading arguments or preserve selected behavior. Currying is not automatically performed by JavaScript. For ordinary functions, consider receiver binding when using bind; arrow functions already capture this lexically.
const add=a=>b=>a+b;const add10=add(10);console.log(add10(3),add(2)(4));Expected output in Node.js:
13 6Each unary call supplies one argument.
const f=(a,b,c)=>a+b*c;const p=f.bind(null,2);console.log(p(3,4),p(5,2));Expected output in Node.js:
14 12Partial application leaves two arguments for later.
Common mistakes
Calling an ordinary two-argument function with one argument does not automatically produce a partially applied function. Avoid unnecessary layers when a direct call is clearer.
Practice
Write a curried discount function and a partially applied three-argument formatter.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Currying versus partial application — Knowledge Check
Reason about the protocol or programming technique and predict the example output.
What is the defining shape of a fully curried three-argument function?
Does partial application have to leave exactly one argument?
Does JavaScript automatically curry ordinary functions?
What is the exact console output in Currying versus partial application example 1?
const add=a=>b=>a+b;const add10=add(10);console.log(add10(3),add(2)(4));What is the exact console output in Currying versus partial application example 2?
const f=(a,b,c)=>a+b*c;const p=f.bind(null,2);console.log(p(3,4),p(5,2));