/*Anonymous function with parameter, executed immediately*/
(function(foo, bar){
alert(foo*bar);
})(2,3);
Interestingly anonymous functions used to create closures. Closure is protected variable space.
Consider the following function
(function(){
var foo=2;
var bar=3;
mul = function(){
alert(foo*bar);
}
})();
You won’t get any alerts after its execution. but
mul();
will give an alert !
After anonymous function’s execution, how can function mul get executed? that too accessing its foo and bar?
Will update the post soon!!!