IIFE – Immediately Invoked Function Expressions (a.k.a. self-executing functions)

Why?

It’s all about variable scoping. Variables declared in the self executing function are, by default, only available to code within the self executing function. This allows code to be written without concern of how variables are named in other blocks of JavaScript code.

 

Example:

(function() {
  var foo = 3;
  console.log(foo);
})();

console.log(foo);