To make a variable private we have used IIFE in ES5.
//ES5
(function(){
var c=10;
})();
console.log(c);// 'c' can't be accessible outside of the IIFE
But in ES6 we can do this in easier way ,
{
let a =10;
}
console.log(a);
//variable a cannot be accessed outside of the block .because they are blocked scoped.
No comments:
Post a Comment