Why the variable inside function cannot be deleted and outside the function can be deleted?
(function myFunc(){
var colors = ['red','green','blue'];
console.log(delete colors);//cannot be deleted, returns false
})();
console.log(delete colors);// can be deleted, returns true
Another question:
Suppose, there are colors
- variables defined in different function like this -
(function myFunc(){
var colors = ['red','green','blue'];
})();
(function nextFunc(){
var colors = ['one','two','three'];
})();
How can I delete the variable of myFunc only?
I tried console.log(delete myFunc.colors); but seems wrong!