Is the script below in correct form of JavaScript?
function foo(){
return function(x){
alert(x)
}
}
foo()("bar");
↑ ↑
There are 2 parenthesis.
It works but I don’t know if it is in a correct form.
If yes, then is that mean this is also correct?
function foo(){
return function(){
return function(){
return function(){
return function(x){
alert(x)
}
}
}
}
}
foo()()()()("?!?!?!");
It looks strange to me but it does work…
The order of function calls is shown by adding parameters:-
You could make the function return itself so it can be repeatedly called, eg
Nesting is usually to keep variables private, eg
Because precog is declared in the brackets its values, calculated internally by the factorial function, cannot be messed about with.
The function assigned to the variable is called as normal:-