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
  • 34,719
  • 24
  • 185
  • 251
Jim Fahad
  • 615
  • 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
  • 303,455
  • 27
  • 380
  • 377