JavaScript learning notes (2) js object_basic knowledge

Source: Internet
Author: User
JavaScript learning notes (2) js object learning. For more information about js learning, see. JavaScript learning notes (2) js object_basic knowledge

1. Simple Type

Simple javascript types include numbers, strings, Boolean, null, and undefined values. All other values are objects.

2. Object

Objects in javascript are variable key sets. In javascript, arrays, functions, and regular expressions are all objects.

An object is a property container. Each attribute has a name and a value. The attribute name can be any string including an empty string. The attribute value can be any value except the undefined value.

3. object definition method

(1) It is defined literally. For example:

var obj = {"name":"Jim","age":16};

(2) define the new keyword. For example:

var obj = new Object(); obj.name = "Jim"; obj.age = 16;

4. Object Attributes

Get the object property value:

Var obj = {"name field": "Jim", "age": 16}; var name = obj ["name field"]; // when the property string is a variable or is not a legal identifier, you can use var age = obj. age; // priority. However, when the attribute string is a constant and the attribute string is a valid identifier

| The operator can be used to fill in the default property value:

var status = flight.status || “unkown”;

The attribute values of an object can be updated using the value assignment statement:

obj.age = 20;

Objects are passed through references.

Properties in the prototype chain can also be accessed in the object.

The delete operator can be used to delete object attributes.

The above is the basic knowledge of JavaScript learning notes (2). For more information, see PHP Chinese website (www.php1.cn )!

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.