Home > Web Front-end > JS Tutorial > JavaScript study notes (2) js object_basic knowledge

JavaScript study notes (2) js object_basic knowledge

PHP中文网
Release: 2016-05-16 18:00:15
Original
1193 people have browsed it

JavaScript study notes (2) js object_basic knowledge

1. Simple types

The simple types of JavaScript include numbers (Number ), string (String), Boolean value (Boolean), null value and undefined value. All other values ​​are objects.

2. Object

Objects in JavaScript are variable keyed collections. In JavaScript, arrays, functions, and regular expressions are all objects.

Objects are containers of properties. Each of these properties has a name and value. The name of an attribute can be any string, including the empty string. Property values ​​can be any value except undefined.

3. Object definition method

(1) Use literal definition. For example:

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

(2)new keyword definition. For example:

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

4. Attributes of the object

Get the attribute value of the object:

< The 🎜>
var obj = {"name field":"Jim","age":16}; 
var name =obj["name field"] ; //属性字符串是变量或者不是合法标识符时可以使用 
var age =obj.age ; 
//优先考虑使用。但当属性字符串是常量,而且属性字符串是合法的标识符时,才能使用
Copy after login
|| operator can be used to fill in default property values:



var status = flight.status || “unkown”;
Copy after login
The property values ​​of an object can be updated through assignment statements:



obj.age = 20;
Copy after login
Objects are passed by reference.


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

delete operator can be used to delete attributes of an object.

The above is the content of JavaScript study notes (2) js object_basic knowledge. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template