Why we use Immediately Invoking functions in javascript ? to avoid polluting the global namespace. Whatever we declare in IIFE, those things won't be available in global scope. You can do the same in a simple block in ES6, the keywords like let, const won't pollute global scope. See below examples

Using ES5

Observe below code
(function () { // open IIFE
var tmp = ···;
···
}()); // close IIFE
console.log(tmp); // ReferenceError
Click here to see DEMO

Using ES6

Observe below code, Using simple block with let, const keywords are enough 
{ // open block
let tmp = ···;
···
} // close block

console.log(tmp); // ReferenceError
Click here to see DEMO

0 comments:

Blogroll

Catagories

Popular Posts