In javascript, we can call function Immediately like the below code. we know every function needs to call after determine. but in this case, we can call the function togetherly.
(function () {
console.log('hello')
})();
// example 2
let x = (function(){
return "my";
})();
console.log(x)
Remember Expression means its produce value and it will be inside first brackets.
Sometimes we need a local clouser environment because we know if we use multiple variables with the same name its have many possibilities for conflict with each variable. So if we are using the same name variable within a function expression it has no chance to replace the value or some things. Because the IIFE function creates a local clouser where the variable data is saved then we can use it anywhere.
Top comments (0)