function (){
alert("hello");
};
Run this Code
Compose this code in bracket ( ); as any code expression can be written like c = (a+b); or c= a+b;
alert("hello");
};
Run this Code
Syntax Error: function statement requires a name
function (){ alert("hello"); }(); |
so,
(function (){
alert("hello");
});
Run
Output: function() ///Success
Now Run this code just after declaration using ( ); after code like-
(function (){
alert("hello");
})();
Run
Popup "hello"
So you can save memory because not defining variable name for this function. But this function can't be called further more. If you need to run function only one time than this idea can save your memory.