Friday 29 August 2014

JavaScript Self Invoking Function Run Without Declare Name To Save Memory

function (){
alert("hello");
};

Run this Code

Syntax Error: function statement requires a name

function (){
alert("hello");
}();


Compose this code in bracket ( ); as any code expression can be written like c = (a+b); or c= a+b;

so,

(function (){
alert("hello");
});

Run


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.

0 comments:

Post a Comment