Open In App

Currying function in JavaScript

Last Updated : 12 Feb, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

Currying is a technique in functional programming where a function is broken into a series of partially applied functions, each taking a single argument. This technique allows for more flexibility and reusability of the code. JavaScript allows us to create a currying function using closures. To make a currying function make a function that returns another function and that returning function uses the argument of the parent function too, so on running the parent function we get a new function which on run does some work with both the arguments.

Example: To demonstrate the currying function using closure in JavaScript.

Javascript




function sum(a) {
  return function (b) {
    console.log(a + b);
  };
}
sum(2)(3);


Output

5

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads