0

I am looking at a JavaScript file, and it is formatted as follows:

;(function() {

    // functions and stuff

})();

What does this mean, and what is this 'technique' called?

scottysseus
  • 1,922
  • 3
  • 25
  • 50

3 Answers3

1

Immediately-invoked function expression

GMaiolo
  • 4,207
  • 1
  • 21
  • 37
1

Its called Immediately-Invoked Function Expressions (IIFEs) like

// variant 1

(function () {
  alert('Woohoo!');
})();

// variant 2

(function () {
  alert('Woohoo!');
}());

You can read more about it here

Ali Baig
  • 3,819
  • 4
  • 34
  • 47
0

This is an anonymous self-executing function.

I would refer you to these resources as of why: https://en.wikibooks.org/wiki/JavaScript/Anonymous_functions
http://esbueno.noahstokes.com/post/77292606977/self-executing-anonymous-functions-or-how-to-write

Antony
  • 1,253
  • 11
  • 19