Just a general note, you can’t delete everything


I’ve had this discussion a couple of times now with several people and maybe It’s about time to make a post for it here :)

The delete operator in ECMAScript-262 can only be used to delete dynamically created variables/properties. Having that said heres a code sample:

var foo = "test"; //executing this in the global window-scope will actually create window.foo and it's being considered as a  dynamically created property on the window object.
delete foo;  //will return true, success
alert(foo); //throws a javascript exception since foo is deleted, thus being undefined

On the other hand…

(function(){
var foo ="test";  //local to the anonymous function, could as well be in a named function.
delete foo;  //will return false, failure to delete
alert(foo);  //will alert "test", delete had no affect
})();
  1. No comments yet.
(will not be published)