currying in js code example
Example 1: currying in javascript
function volume(w, h, l) {
return w * h * l;
}
volume(4, 6, 3);
function volume(w) {
return function(h) {
return function(l) {
return w * h* l;
}
}
}
volume(4)(6)(3);
Example 2: what is currying
a technique that applies a function
to its arguments one at a time, with
each application returning a new function
that accepts the next argument.
Example 3: currying javascript
const multiply = (a) => (b) => a*b;
multiply(3)(4);
const multipleBy5 = multiply(5);
multipleBy5(10);
Example 4: what is currying in javascript example
Uses of currying function
a) It helps to avoid passing same variable again and again.
b) It is extremely useful in event handling.
syntax:
function Myfunction(a) {
return (b) => {
return (c) => {
return a * b * c
}
}
}
myFunction(1)(2)(3);
Example 5: currying in javascript
Uses of currying function
a) It helps to avoid passing same variable again and again.
b) It is extremely useful in event handling.
syntax:
function Myfunction(a) {
return (b) => {
return (c) => {
return a * b * c
}
}
}