1
//anonymous 1
(function(){
    $('something').first().addClass("anything");
});

//anonymous 2
(function(){
    $('something').first().addClass("anything");
})();

What is the actual and practical difference between these two?

(function(){

});

and

(function(){

})();
Cœur
  • 37,241
  • 25
  • 195
  • 267
Jim Fahad
  • 635
  • 1
  • 8
  • 21

1 Answers1

8

The first one is never called, it's just a function

(function(){

}); // never called

The second one adds the parentheses at the end, which calls the function immediately, which is why it's called an immediately invoked function expression

(function(){

})(); // called now
adeneo
  • 312,895
  • 29
  • 395
  • 388