var result = (function () {
var name = "Barry";
return name;
})();
// Immediately creates the output:
result; // "Barry"
//expression that are immediately invoked and executed as soon as defined.
//this aviod global scope pollution.
//syntax
(function(a,b){
return a + b;
})(10,20);
//You can also use an arrow function in defining an IIFE:
(() => {
//...
})();
(function () {
// code goes here
})();