IIFE - Iimmediatelly Invoked Function Expression


    var foo = "foo1";

    (function() {
        var foo = "foo2";
        console.log(foo);  // foo2
    })();


    console.log(foo); // foo1

    // we can also write the above statement like:
    (function() {
        // code
    }());

We use IIFE in order to not pollute the global scope.

Bibliography: <br/ > Ben Alman: Immediately-Invoked Function Expression (IIFE)

comments powered by Disqus