The delete operator is a unary operator that deletes the attributes, array elements, or variables of objects specified by the Operation number. If the delete operation is successful, true is returned. If the number of operations cannot be deleted, false is returned. Note that deleting attributes, variables, or array elements does not just set their values to undefined. When an attribute is output, it no longer exists. Not all attributes and variables can be deleted. Some internal core attributes and client attributes cannot be deleted, and User-Defined variables in the VaR statement cannot be deleted. If the number of operations used by delete is a non-existent attribute, true is returned.
VaR o = {X: 1, Y: 2}; // defined a variable; initialize to object
Detele O. X; // delete one of the other properties; return true
Typeof O. X; // property does not exist; Return "undefined"
Delete O. X; // delete a nonexistent property; return true
Delete O; // can't delete a declared variable; return false
Delete 1; // can't delete an integer; return true
X = 1; // implicity declared a variable without var keyword
Delete X; // can delete this kind of variable; return true
X; // runtime error: X is not defined
Delete only affects attribute values and does not affect objects referenced by these attributes:
VaR my = new object (); // create an object named "my"
My. Hire = new date (); // my. Hire refers to a date objct
My. Fire = My. Hire; // my. Fire refers to the same object
Delete my. Hire; // hire property is deleted; return true
Docunment. Write (My. Fire); // but my. Fire still refers to the date object