var x = 1;
var output = (function() {
delete x;
return x;
})();
console.log(output);
Is "delete" statement restricted only to objects?
delete
can only be used to remove object properties; it can't undeclare a variable (see MDN about it).
If you need to use this functionality, assign x
to window
:
window.x = 1;
var output = (function() {
delete window.x;
return window.x;
})();
console.log(output);
Note: Generally, cluttering up the window
object is bad practice and should be avoided if at all possible.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With