function firstFunction(num, callback) {
callback(num);
};
function secondFunction(num) {
return num + 99;
};
console.log(firstFunction(56, secondFunction));
undefined
If I call console.log
from within secondFunction
, it returns the value.
Why not? What's the point of setting up callbacks if I can't get the value out of them to use later? I'm missing something.
In your function
firstFunction
, you do:Which evaluates to
Which is then
But you never return the value! Without a return value, a function will simply evaluate to
undefined
.Try doing this:
firstFunction
does not return anything, plain and simple! That is why when youconsole.log
the return value, it isundefined
.The code in question:
calls
callback
and then does nothing with the returned value. You want: