What is Currying Function in JavaScript? (original) (raw)

Last Updated : 07 Mar, 2025

Currying is used in JavaScript to break down complex function calls into smaller, more manageable steps. It transforms a function with multiple arguments into a series of functions, each taking a single argument.

// Normal Function // function add(a, b) { // return a + b; // } // console.log(add(2, 3));

// Function Currying function add(a) { return function(b) { return a + b; } }

const addTwo = add(5); // First function call with 5 console.log(addTwo(4));

`

**In this example

How Currying Works in JavaScript?

Currying function in the JavaScript can be done manually, but it can also be done using the closure. Below it is shown that how currying function works.

Currying with Arrow Functions

Arrow function can be used to make currying function short:

JavaScript `

const add = a => b => a + b; console.log(add(5)(4));

`

This syntax is shorter and doining the same thing as the earlier example.

Advantages of Currying Function

When to Use Currying in JavaScript?

In JavaScript, currying function is used in the following cases: