DEV Community

Discussion on: Currying in JavaScript

Collapse
 
safinghoghabori profile image
Safin Ghoghabori • Edited

I have one question please answer it and clear my dillema:

//below is currying function
const sum = a => {
return (b) => {
return a+b;
}
}

So my query is why we need to nest functions and make it currying? Why cant we simply define it as follow:

const sum = (a,b) => a+b;

In this way, we also pass a & b, whereas in first example we also pass a & b, then what is difference? What are advantages?

I didnt see anything about this, elaborate on this would be appreciated.

Thanks in advance!