Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Differences between (func(){}()); vs (func(){})(); [duplicate]

Tags:

javascript

I commonly see both conventions and I'm wondering if there's an actual difference.

(function () {
  document.write("it works");
}());

(function () {
  document.write("it also works");
})();
like image 243
GraxRabble Avatar asked Oct 12 '13 09:10

GraxRabble


1 Answers

There no difference between the two , The opening brace serves as a syntactic hint to tell the parser that what follows is a function expression instead of a function declaration.

for more http://jsperf.com/self-invoking-function

like image 146
user2092317 Avatar answered Oct 26 '22 11:10

user2092317