0Pricing
JavaScript Academy · Lesson

Currying Functions

Transform multi-argument functions into chains.

What Is Currying?

Currying transforms a function that takes many arguments into a sequence of functions that each take one argument.

Instead of add(1, 2, 3) you call add(1)(2)(3). Each call returns the next function until all arguments are collected.

Currying By Hand

The clearest way to see currying is to write nested functions, each returning the next one and closing over the earlier arguments.

function add(a) {
  return function (b) {
    return function (c) {
      return a + b + c;
    };
  };
}

console.log(add(1)(2)(3));

All lessons in this course

  1. Partial Application
  2. Currying Functions
  3. Function Composition
  4. Building pipe and compose
← Back to JavaScript Academy