Intermediate JavaScript Interview QuestionsIntermediateComparison
JavaScript · Question 67
What is the difference between currying and partial application in JavaScript?
Direct answer
Currying transforms a multi-argument function into a sequence of single-argument functions, while partial application fixes some arguments now and returns a function for the remaining arguments without requiring one argument per level.
If add(a,b,c) becomes add(a)(b)(c), that is currying. If add(1,2,3) becomes a new function such as addOne = (...rest) => add(1, ...rest), that is partial application.
- Currying can make function composition and staged configuration expressive.
- Partial application is often simpler when you only want to preconfigure a few leading/context arguments.
Function.prototype.bind()can provide a form of partial application for leading arguments in addition to bindingthis.- JavaScript functions are not automatically curried; currying is a transformation/pattern you implement or obtain from a library.
A practical example is creating a configured validator or logger once and reusing the returned function rather than passing the same configuration on every call.