Best Division

Spread Your Knowledge

  • All topics
  • About us
  • Contact us
  • Privacy policy
  • Terms of service
  • Copyright
  • Facebook
  • Twitter
  • Instagram
  • Youtube
  • LinkedIn
  • Pinterest
  • Github
  • Tumblr

© 2026 Best Division

What Is Currying in JavaScript? Examples and a Curry Helper

JavaScript
Jayant Kumar
Jayant Kumar@jayantkumar314
PublishedDec 6, 2026
6 min read

Currying in JavaScript is a technique that turns a function taking several arguments into a chain of functions that each take one argument. Instead of calling add(1, 2, 3), you call add(1)(2)(3). The main payoff is partial application: you fix some arguments early and get back a smaller, reusable function. This guide builds on closures and pure functions, because currying works by remembering earlier arguments in a closure.

JavaScript has no built-in curry, but you can write one in a few lines.

Table of Contents

  • What currying means
  • Currying versus partial application
  • A generic curry function
    • Limits of the length trick
  • Practical examples
    • Building specialised functions
    • Reusing logic in array pipelines
    • Configuring a logger or request helper
  • When currying helps and when it does not
  • Frequently Asked Questions
    • Is currying the same as partial application?
    • Does JavaScript have a built-in curry function?
    • Why does currying use closures?
    • Does currying make code faster?
  • Summary
  • Related Articles

What currying means

A normal function takes all its arguments at once. A curried function takes them one at a time and returns a new function until it has everything it needs.

javascript
javascript
Loading syntax highlighting...

Each call returns a function that closes over the arguments received so far. Only the last call computes the result. The number of arguments a function expects is called its arity, and currying converts an n-ary function into n unary functions.

Currying versus partial application

The two ideas are related but not identical.

IdeaWhat it doesExample
CurryingConverts f(a, b, c) into f(a)(b)(c)addCurried(1)(2)(3)
Partial applicationFixes some arguments and returns a function for the restadd.bind(null, 1)

A curried function makes partial application natural, because calling it with fewer arguments already returns a function waiting for the rest.

javascript
javascript
Loading syntax highlighting...

You can also do partial application without currying by using Function.prototype.bind:

javascript
javascript
Loading syntax highlighting...

A generic curry function

The arrow-function style above has to be written by hand for every function. A reusable curry helper reads the function's length property, which is the number of declared parameters, and keeps collecting arguments until it has enough.

javascript
javascript
Loading syntax highlighting...

This version accepts any grouping of arguments. When the collected arguments reach fn.length, it calls the original function. Libraries such as Lodash (_.curry) and Ramda (R.curry) provide the same idea with extra features.

Limits of the length trick

fn.length does not count rest parameters or parameters with default values. A function declared as function f(a, b = 2, ...rest) has a length of 1, so curry would call it after the first argument. For such functions, pass the arity explicitly in your own helper or avoid currying them.

Practical examples

Building specialised functions

javascript
javascript
Loading syntax highlighting...

Reusing logic in array pipelines

Currying fits well with map and filter, which pass exactly one value to your callback.

javascript
javascript
Loading syntax highlighting...

Without currying you would write n => isGreaterThan(n, 5) each time. The curried form reads like a sentence and the callbacks are named and reusable.

Configuring a logger or request helper

javascript
javascript
Loading syntax highlighting...

When currying helps and when it does not

Currying helps when:

  • you call the same function repeatedly with one argument fixed
  • you want small, named, composable functions for map, filter and pipelines
  • you build function composition with helpers such as compose or pipe

It is a poor fit when:

  • a function has optional or variable arguments, because the arity is unclear
  • the team does not know the style, since f(a)(b)(c) can surprise readers
  • performance is critical in a hot loop, because each call creates a new closure

Choose argument order carefully. Put the arguments that change least first (such as configuration) and the data last, so partial application produces useful functions. This is why functions like map(fn)(list) take the data last in functional libraries.

Frequently Asked Questions

Is currying the same as partial application?

No. Currying always turns a function into a chain of single-argument functions. Partial application fixes any number of arguments at once and returns a function for the remainder. Currying makes partial application convenient.

Does JavaScript have a built-in curry function?

No. You write one yourself, as shown above, or use a library such as Lodash or Ramda. The language only gives you the building blocks: closures, arrow functions and bind.

Why does currying use closures?

Each returned function needs to remember the arguments from earlier calls. A closure keeps those values alive without any global variable.

Does currying make code faster?

No. It is a way to organise code, not an optimisation. Each step creates a function, so it adds a small cost rather than removing one.

Summary

Currying converts a multi-argument function into a sequence of one-argument functions, each remembering earlier arguments through a closure. Use it to create specialised, reusable functions and to feed map and filter. A generic curry helper based on fn.length works for fixed-arity functions, but it breaks with default or rest parameters. Order your parameters so the data comes last.

Related Articles

  • What is functional programming in JavaScript?
  • What Is Memoization in JavaScript and How Do You Use It?
  • Learn JavaScript: Complete Study Roadmap, Beginner to Advanced
Share

Similar posts

  • What Are Pure Functions and Side Effects in JavaScript?
  • How does recursion work in JavaScript?
  • What is an IIFE in JavaScript and why use it?
  • What is a callback function in JavaScript?
  • What is lexical scope and block scope in JavaScript?
  • How do you write arrow functions in JavaScript?
  • What are rest parameters and spread syntax in JavaScript?
  • How do default parameters work in JavaScript?