javascript - Alternative syntax for self-invoking function? -


while writing javascript course coworkers, accidently discovered alternative syntax self-invoking function. know it, there specifics ? wasn't able find documentation it.

code : classic syntax

    (function(){       console.log("i'm self-invoked!");     })(); 

alternate syntax

    (function(){       console.log("me too!");     }()); 

thanks hints !

the 2 identical in meaning.

in both, ( @ start symbols start of expression. indicates start of a function expression intend invoke. invoke it. difference subtle , should not matter @ all, let's explore it:

(function(){   console.log("i'm self-invoked!"); })(); 

here, ( tell compiler it's start of expression, compiler evaluates expression (a function expression in case) , invokes (outside expression).

(function(){   console.log("me too!"); }()); 

here - invokation pattern ( () ) part of expression.


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -