CodeZettaInterview Hub

JavaScript · Functional Programming · Senior · Comparison

Compare currying and partial application in JavaScript. When is each useful?

Short Interview Answer

Currying transforms a multi-arg function into a chain of unary functions; partial application presets some args and returns a function of the rest.

Detailed Explanation

Currying: `f(a)(b)(c)` style enables compositional pipelines and point-free style. Partial: `partial(f, a)` returns `(b, c) => f(a,b,c)`. JS functions are not auto-curried (unlike some FP languages); libraries (lodash/fp, Ramda) add tooling. Use partial for configuring callbacks (`bind` is a form of partial for `this`/args). Use curry when building many specialized functions from one generic. Trade-offs: curried APIs can confuse teams unused to FP and hurt ergonomics with TypeScript overloads. Prefer clarity for most product code.

Example

const curryAdd = (a) => (b) => a + b;
const add5 = curryAdd(5);
add5(3); // 8

function partial(fn, ...preset) {
  return (...rest) => fn(...preset, ...rest);
}

Interview Tip

Define both crisply — many candidates mix them up.

Common Mistake

Using the terms interchangeably.

Did you know this answer?