What Is Currying in JavaScript?
Currying transforms f(a,b,c) into f(a)(b)(c). Here is how it works and when to use it.
What Is Currying in JavaScript?
Currying transforms a function with multiple arguments into a sequence of functions that each take one argument.
Example
// regular: f(a, b, c) function add(a, b, c) { return a + b + c; } add(1, 2, 3); // 6 // curried: f(a)(b)(c) function curriedAdd(a) { return function (b) { return function (c) { return a + b + c; }; }; } curriedAdd(1)(2)(3); // 6
Generic curry Function
function curry(fn) { return function curried(...args) { if (args.length >= fn.length) return fn(...args); return (...next) => curried(...args, ...next); }; } const sum = curry((a, b, c) => a + b + c); sum(1)(2)(3); // 6 sum(1, 2)(3); // 6 sum(1)(2, 3); // 6
Use Cases
- Partial application: preset some arguments:
const add5 = sum(1)(2); add5(3); - Function composition: chain small functions.
- Reusable configurations:
const log = curry((level, msg) => ...); const info = log("info");
The Takeaway
Currying transforms f(a, b, c) into f(a)(b)(c). Use the generic curry function with recursion. Use cases: partial application, composition, and configurable functions. Closures make currying possible (each returned function closes over previous arguments).
Transforming a function with multiple arguments into a sequence of single-argument functions: f(a, b, c) becomes f(a)(b)(c). Each call returns a function that takes the next argument.
Return a function that collects arguments. If enough arguments (args.length >= fn.length), call the original. Otherwise, return a new function that collects more. Use recursion.
Currying transforms into one-argument-at-a-time: f(a)(b)(c). Partial application presets some arguments and returns a function for the rest: f'(b, c) with a preset. Currying is one-at-a-time; partial is some-now.
Partial application (preset arguments), function composition (chain small functions), and reusable configurations (e.g., const info = log('info')). Closures make it possible.
Yes. Each returned function closes over the accumulated arguments. The closure keeps the arguments alive between calls. Without closures, currying would not work.
Ready to master React completely?
Want to upskill yourself, crack your next interview, and get your dream job? Join our comprehensive course to dive deeper with high-quality video tutorials, solve interview questions, and a premium community.
Master React
Want to upskill yourself, crack your next interview, and get your dream job? Join our comprehensive course.

