What is Currying in JavaScript?

What is Currying in JavaScript?

Ferenc Almasi • 2020 November 12 • Read time 1 min read
  • twitter
  • facebook
JavaScript

Currying is a technique where you call a sequence of functions with one argument instead of calling one function with multiple arguments. You call a function with the first argument which returns a function, which you call with the second argument and so on:

Copied to clipboard! Playground
// Instead of
const add = (a, b, c) => a + b + c;

add(2, 2, 2);

// Currying does
const curry = (a) => {
    return (b) => {
        return (c) => {
            return a + b + c;
        }
    }
};

curry(2)(2)(2);
currying.js

And why is it called "currying"? According to Wikipedia, the term has been coined by Christopher Strachey back in 1967 as a reference to Haskell Curry who was a mathematician and logician in the 20th century.

An alternative name has also been proposed called "Schönfinkelisation", as a reference to Moses Schönfinkel, a Russian mathematician and logician.

What is currying in JavaScript?
If you would like to see more Webtips, follow @flowforfrank

50 JavaScript Interview Questions
  • twitter
  • facebook
JavaScript
Did you find this page helpful?
📚 More Webtips
Frontend Course Dashboard
Master the Art of Frontend
  • check Access 100+ interactive lessons
  • check Unlimited access to hundreds of tutorials
  • check Prepare for technical interviews
Become a Pro

Courses

Recommended

This site uses cookies We use cookies to understand visitors and create a better experience for you. By clicking on "Accept", you accept its use. To find out more, please see our privacy policy.