I'm encountering an issue with invoking a function within another function. I can't figure out why I am unable to invoke a function using the following logic:
function func1(futurefunc){
futurefunc();
}
function func2(){
return 3+3;
}
func(func2);
The code above returns undefined when it should be returning 6. Strangely, when I use func(alert)
, the alert function is successfully invoked. I'm puzzled as to why one case works while the other doesn't.
However, if I modify the code like this:
function func1(futurefunc){
return futurefunc();
}
Now the code correctly outputs the value of 6. Can anyone provide a clear explanation for this behavior? I want to make sure I'm not missing anything.