javascript - Why does my child function require a 'return' statement to avoid erroring out? The parent function has no 'return' and no error -
var = function(param1) { var b = function(param2) { console.log(param1 + param2); }; return b; }; a(4)(5); // logs "9" is return statement (in case "return b") necessary? why need 1 function here, not other? when necessary, , why?
the expression
a(4)(5) first calls function a parameter 4 (a(4)), returns b (which function). returned function called parameter 5. same if did
c = a(4); c(5); so, need outer function a return function - because treat it's result function. , don't care if inner function b returns don't use result, doesn't matter if returns anything.
Comments
Post a Comment