Possible Duplicate:
Location of parenthesis for auto-executing anonymous JavaScript functions?
Is there a difference between (function() {…}()); and (function() {…})();?
Two ways of immediate call to anonymous function (function(d){ }() ); and (function(x){ } )();
Is there a difference between the given 2 ways of declaring and calling an anonymous function?
Option 1:
(function(){
console.log('Declare and call anonymous function');
})();
Option 2:
(function(){
console.log('Declare and call anonymous function');
}());
Both the functions are invoked once it is evaluated.But I couldn’t understand the difference.
No, there’s no difference: the two options are syntactically different but semantically equivalent. Consider a named function:
vs.
and perhaps it’s clearer how they’re the same thing.