1var result = (function () {
2 var name = "Barry";
3 return name;
4})();
5// Immediately creates the output:
6result; // "Barry"
1(function () {
2 var aName = "Barry";
3})();
4// Variable aName is not accessible from the outside scope
5aName // throws "Uncaught ReferenceError: aName is not defined"
6
1/*An IIFE (Immediately Invoked Function Expression) is a JavaScript
2function that runs as soon as it is defined
3*/
4
5(function () {
6 //write your js code here
7});