JavaScript · The language round
What is currying and how is it different from partial application?
Short answer
Currying turns a function of several arguments into a chain of one-argument functions. Partial application fixes some arguments now and supplies the rest later. Both rely on closures.
The terms are often used interchangeably, but they describe different transformations. Currying is about the shape of the function. Partial application is about pre-filling arguments.
const add = (a) => (b) => (c) => a + b + c;
console.log(add(1)(2)(3)); // 6
function multiply(a, b) {
return a * b;
}
const double = multiply.bind(null, 2);
console.log(double(5)); // 10add is curried. double is a partially applied version of multiply.A reusable curry helper
function curry(fn) {
return function curried(...args) {
if (args.length >= fn.length) {
return fn.apply(this, args);
}
return (...next) => curried.apply(this, [...args, ...next]);
};
}
const addThree = curry((a, b, c) => a + b + c);
console.log(addThree(1)(2)(3)); // 6
console.log(addThree(1, 2)(3)); // 6- Currying always produces unary functions in the strict sense
- Partial application can fix any number of arguments at once
- Both create new functions through closures
bindis a built-in form of partial application
Follow-ups you should expect
Interviewers use these to check whether the first answer was understanding or memorisation.
- 1What is the difference between currying and partial application?
- 2How does `bind` perform partial application?
- 3How would you implement a generic `curry` function?
- 4Where is currying useful in real code?
Say it in the interview
Currying transforms a function that takes several arguments into a chain of functions that each take one argument. Partial application fixes some arguments now and leaves the rest for later. Both use closures. bind is a built-in partial application. I use currying when I want composable functions or specialised versions, but I do not force it when a normal function is clearer.
Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.
Related questions
Reading is step one
Now say it out loud.
Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live JavaScript mock interview and get scored feedback on depth, clarity and confidence.