What is currying? Implement a curry that supports add(1)(2)(3) and add(1,2)(3).
Quick answer
Currying transforms f(a,b,c) into a chain of unary-ish calls. Collect args until you reach the function's arity, then invoke.
In detail
Currying turns a multi-arg function into a sequence of calls, enabling partial application. Compare accumulated args against `fn.length`; if satisfied, call; otherwise return a function that gathers more — another closure-driven pattern.
1function curry(fn) {
2 return function curried(...args) {
3 return args.length >= fn.length
4 ? fn.apply(this, args)
5 : (...rest) => curried.apply(this, [...args, ...rest]);
6 };
7}
8const add = curry((a, b, c) => a + b + c);
9add(1)(2)(3); // 6
10add(1, 2)(3); // 6Why interviewers ask this: Common product-company question on closures + functional style.
This is 1 of 118+ questions in the JavaScript Interview Kit
Get every question with detailed answers, follow-ups and real code — plus coding challenges and a last-minute revision sheet. One-time payment, instant access.
⚡ Get the JavaScript Interview Kit → ₹299