The delete operator removes a property from an object. Its single operand should be a property access expression.
JavaScript: The Definitive Guide, 6th Edition
delete is used to remove a properpty from an object.
vara={x:2,y:3};deletea.x;// Returns true; `a` is changed to be {y: 3}
But there are circumstances that we may expect the wrong result from it. Here’s what JavaScript: The Definitive Guide tells us.
A delete expression evaluates to true if the delete succeeded or if the delete had no effect (such as deleting a nonexistent property). delete also evaluates to true when used (meaninglessly) with an expression that is not a property access expression:
o={x:1};// o has own property x and inherits property toString
deleteo.x;// Delete x, and return true
deleteo.x;// Do nothing (x doesn't exist), and return true
deleteo.toString;// Do nothing (toString isn't an own property), return true
delete1;// Nonsense, but evaluates to true
deletea.x;// returns true and `a` is changed to be {y: 3}
delete does not remove properties that have a configurable attribute of false. (Though it will remove configurable properties of nonextensible objects.) Certain properties of built-in objects are nonconfigurable, as are properties of the global object created by variable declaration and function declaration. In strict mode, attempting to delete a nonconfigurable property causes a TypeError. In non-strict mode (and in ECMAScript 3), delete simply evaluates to false in this case:
deleteObject.prototype;// Can't delete; property is non-configurable
varx=1;// Declare a global variable
deletethis.x;// Can't delete this property
functionf(){}// Declare a global function
deletethis.f;// Can't delete this property either
JavaScript: The Definitive Guide, 6th Edition
As mentioned several times above, what is configurable?
The configurable attribute controls at the same time whether the property can be deleted from the object and whether its attributes (other than writable) can be changed.
We know that y, an undeclared variable can be used in almost the same way like declared variables like x. Then, how are they different in this case?
Matt Coughlin gives a very clear answer to this question, which I’d suggest reading. To be brief, for declared global variables, the configurable attribute is false. For undeclared global variables, it’s true. And properties can be deleted only when it’s configurable attribute is true.