JavaScript Learning Notes Object

Source: Internet
Author: User
Tags access properties

object is the core concept of JavaScript and the most important data type. All of JavaScript's data can be treated as objects.

Simply put, the so-called object, is an unordered set of data, by a number of "key-value pairs" (key-value) composition.

To create an object:

1. Use the new operator followed by the object constructor

2. Object literal notation

When using literal syntax, a property can also use a string

Numeric property names are automatically converted to strings

In fact, the object literal is also the preferred way to pass a large number of optional parameters to the function, which is to pass the object as a parameter to the function;

There are two ways to access object properties:

Dot notation (person.name) and bracket notation (Person[name] or person["name"])

There is not much difference between the two methods, the main advantage of the square bracket syntax is that the property can be accessed through a variable

You can also use square brackets if the property name contains a property name that does not conform to a grammar rule or if you are using a keyword or reserved word

It is generally recommended that you use point notation unless you must use variables to access properties.

To view all the properties of the object itself (Object.keys):

Delete Property (remove):

The trouble is that if you delete a nonexistent property, delete does not error and returns TRUE.

The delete command can only be used to guarantee that the value of a property is undefined, and there is no guarantee that the property really exists.

In only one case, the delete command returns FALSE, that is, the property exists and must not be deleted.

JavaScript Learning Notes Object

Related Article

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.