1

Both of these functions below are self-invoking functions. Can anyone explain to me what is difference between these two? I've looked around a lot of places. But I've not been able to find anything.

First Type

(function(){
    console.log('Hello world');
}());

Second Type

(function(){
    console.log('Hello world');
})();
p.matsinopoulos
  • 7,655
  • 6
  • 44
  • 92
Kaushik
  • 2,072
  • 1
  • 23
  • 31

1 Answers1

4

They're the same. They're just two different but similar ways to force the JS engine correctly interpret the function expression.

Another way would be for example

+function(){
    console.log('Hello world');
}() 

The most usually accepted convention is to put the parenthesis around the function expression :

(function(){
    console.log('Hello world');
})();
Denys Séguret
  • 372,613
  • 87
  • 782
  • 758