Delete operators in Javascript

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.