Hello everyone, explain this program
function multiplier(factor) {
return number => number * factor;
}
let twice = multiplier(9);
console.log(twice(10));
// → 90
Hello everyone, explain this program
function multiplier(factor) {
return number => number * factor;
}
let twice = multiplier(9);
console.log(twice(10));
// → 90
Your multiplier function returns a function with one parameter number (it’s your arrow function : the F function below).
So multiplier(9) returns a function F where factor is 9 then when you call twice(10) you just call this returned function F with number set to 10. This function F returns a number = number * factor = 10 * 9 = 90.
thank you so much
You’re welcome
This is an example of currying. See https://hackernoon.com/currying-in-js-d9ddc64f162e for a more general discussion on this topic
thanks…