The delete operator removes a property from an object. Its single operand should be a property access expression.
delete is used to remove a properpty from an object.
deleteexpression evaluates to
trueif the delete succeeded or if the delete had no effect (such as deleting a nonexistent property).
deletealso evaluates to
truewhen used (meaninglessly) with an expression that is not a property access expression:
deletedoes 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),
deletesimply evaluates to
falsein this case:
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.
Be careful when deleting on global objects. Here are some interesting results that may be confusing.
Why? How is
x different from
y in this case?
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