Passing functions to other functions
Let's take the following as an example:
function invokeAdd(param) {
return param;
}
Try logging out a function like this.
function invokeAdd(param) {
return param;
}
console.log(invokeAdd)
You will notice that in the console it will show you the function definition since that is what the invokeAdd
variable is storing.
Now let's try logging the function with arguments.
function invokeAdd(param) {
return param;
}
console.log(invokeAdd("test"))
You'll notice you'll get the return value
for the function that is the argument
we passed.
So when you try console.log(invokeAdd(one(8), two));
Your first parameter is essentially passing the result of one(8)
not the actual function.