Currying Function In JavaScript

Deepa Jarout
2 min readFeb 16, 2023

--

Currying, a technique used in functional programming, allows you to turn a function with numerous arguments into a series of nesting functions in JavaScript. It gives back a new function that anticipates the following parameter inline.

In other words, rather than accepting every argument at once, a function accepts the first one and returns a new function, which accepts the second and returns a new function, which accepts the third, and so on, until every argument has been satisfied.

What is JavaScript Currying Function?
In JavaScript, currying converts a function with several arguments into a sequence of nested functions, each of which only accepts one argument. Currying aids in the development of higher order functions and helps you avoid passing the same variable more than once.

Specifically, when we change a function call from multiply(1,2,3) to multiply(1)(2) (3).

A function’s arity is another word for the number of arguments it accepts.

two-arity function by deepajarout
two-arity function by deepajarout
three-arity function by deepajarout
three-arity function by deepajarout

multiply is a two-arity function that accepts two arguments, and multiply accepts three arguments (three-arity function).

Curried functions are built by chaining closures and simultaneously defining and returning their inner functions.

--

--

Deepa Jarout

I am Software developer.I like problem solving, traveling, photography, dancing, video games, conversation.I like to explore new places with different tradition