- IIFE - Immidiately Invoked Function Expression
- Once the file is loaded, IIFE invokes- there is no need to call function name bracket
().
function test(){
console.log('hello');
}
test(); //<--invoked test.js
- Once test.js is loaded, below function is invoked.
(function (){
console.log('hello');
})(); //<-- Invokedmain.js
"use strict";
(function () {
var thing = {"hello": "main"};
console.log(thing);
})();other.js
"use strict";
(function () {
var thing = {"hello": "other"};
console.log(thing);
})();index.html
<!DOCTYPE html>
<html lang="en">
<body>
<script src="main.js"></script>
<script src="other.js"></script>
</body>
</html>Result of executing index.html
{hello: "main"}
{hello: "other"}