Explain currying and partial application in JavaScript
Learn how to transform functions into reusable, smaller functions using currying and partial application.
Question
Explain currying and partial application in JavaScript.
Answer
Currying transforms a function with multiple parameters into a sequence of functions that take one parameter at a time.
function multiply(a) {
return function (b) {
return a * b;
};
}
const double = multiply(2);
console.log(double(5)); // 10
Partial application pre-fills some arguments of a function:
function add(a, b, c) {
return a + b + c;
}
const add5 = add.bind(null, 5);
console.log(add5(10, 2)); // 17
Real-World Example
Used in React/Node to create specialized functions from generic ones — e.g. makeApiClient(baseUrl).
Quick Practice
Write a curried version of a function that adds two numbers: add(a)(b) → returns a + b.
Summary
Currying = break into smaller functions. Partial = pre-fill arguments. Both improve reusability.
Is currying the same as partial application?
Not exactly. Currying turns a function of N args into N functions of 1 arg. Partial application pre-fills some arguments.
Stay Updated
Get the latest frontend challenges, interview questions and tutorials delivered to your inbox.