DEV Community

Trishank Sharma
Trishank Sharma

Posted on

Currying in JavaScript

Currying is the pattern of writing the functional code more modular. In simple words.

Currying is the pattern where a function with multiple arguments is transformed into a series of functions, each taking a single argument.

Instead of taking all arguments at once, the curried function takes the first argument, returns a new function that takes the next argument, and so on until all arguments are provided. The final function then returns the result.

//Normal Function
 `function nonCurrying(param1, param2, param3){
  return param1 + param2 + param3
}`

// Curried Function

`function curried(param1){
   return function(param2){
    return function(param3){
      return param1 * param2 * param3
}}}

curried(10)(20)(30);
`





Enter fullscreen mode Exit fullscreen mode

Top comments (0)