iffy js code example

Example 1: IFFI in js

// This function will be invoked right away we don't have to call it
(function () {
	console.log("This is an IIFE"); 
})();

Example 2: iife

(function () {
    var aName = "Barry";
})();
// Variable aName is not accessible from the outside scope
aName // throws "Uncaught ReferenceError: aName is not defined"

Example 3: iife

/*An IIFE (Immediately Invoked Function Expression) is a JavaScript 
function that runs as soon as it is defined
*/

(function () {
        //write your js code here
});