-2

What does the following code mean in JavaScript :

(function() {

})();
iJade
  • 23,144
  • 56
  • 154
  • 243

2 Answers2

0

Thats a singleton/IIFE (immediately invoked function expression).

Using an IIFE can be helpful when wanting to use a local scope which eliminates binding to global objects like the window.

There is also a slight performance benefit to this approach as you can pass in commonly used objects to the anonymous function. JavaScript first looks for a property in its local scope then works up the chain.

Simon Staton
  • 4,345
  • 4
  • 27
  • 49
0

It is a Self-Invoking Anonymous Function.

A self-invoking anonymous runs automatically/immediately when you create it and has no name, hence called anonymous.

More info

silentw
  • 4,835
  • 4
  • 25
  • 45
  • 4
    It's not self-invoking (the code calling it is not part of the function). It *is* immediately-invoked. The standard term is IIFE (immediately invoked function expression). – T.J. Crowder Jan 09 '15 at 12:11