I've seen a code like this:
function operationType(type){
return function(a,b){
console.log(`It's a ${type}`);
return a+b;
}
}
const sum=operationType(type);
has only one parameter called type
? It looks like when i call the sum
function it's only consider the returned function
And what i don't understand is they way arguments are passed when the function is called like this sum(4,4)
and returns :
It's and addition
8
How can we call the function sum(4,4)
when the operationType(type)
function is function that's is really defined.
What I really want to say is here : const sum=operationType('addition')
we do not pass the anonymous function that calculate the sum,how does it guesses??
How can sum(4,4) = operationType('addition')
.I'm really lost