Horje
Currying function in JavaScript

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



Reffered: https://www.geeksforgeeks.org


Advanced Javascript


Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
9