DEV Community

Mahin Tazuar
Mahin Tazuar

Posted on

What is Currying in JavaScript

hascale curry brough this code pattern. That is not new concenpt , Its just a code pattern which is brough hascale curry.This defination is converting a function which has multiple perameter and converted to a single perameter.
Example : -

function curryFunc(x){
  return function(y){
    return function(z){
      return x+y+z;
    }
  }
}
console.log(curryFunc(1)(2)(3))
Enter fullscreen mode Exit fullscreen mode

Its based one things , we want to decrease function perameter.
When this function call by first time or first function call with paremeter. This function call partial function.
Example: -

function curryFunc(price){
  return function(disc ){
      return price+disc;
  }
}
const user1 = curryFunc(3) // that is called partial function
const result = user1(35)
console.log(result)
Enter fullscreen mode Exit fullscreen mode

Top comments (0)