JavaScriptMedium
What is currying and how does it work?
By FrontendPro Editorial Team Updated 8/8/2026
#JavaScript
Answer
Currying is a technique in functional programming where a function that takes multiple arguments is transformed into a series of functions that each take a single argument. This allows for partial application of functions. For example, a function f(a, b, c) can be curried into f(a)(b)(c). Here's a simple example in JavaScript:
js
function add(a) {
return function (b) {
return function (c) {
return a + b + c;
};
};
}
const addOne = add(1);
console.log(addOne); // function object
const addOneAndTwo = addOne(2);
console.log(addOneAndTwo); // function object
const result = addOneAndTwo(3);
console.log(result); // Output: 6
