I was taking a small test online and there was this code:
function getFunc() {
var a = 7;
return function(b) {
alert(a+b);
}
}
var f = getFunc();
f(5);
I would like to know why I can't call getFunct(5)
directly for example.
I don't understand the last two lines.
Why do I need to assign the function to a variable. What happens when doing f(5)?
How does JS interpret that the 5 is a variable for the inner function and not the outer?