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

JavaScript study notes (2) js object_basic knowledge

PHP中文网
PHP中文网Original
2016-05-16 18:00:151136browse

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};

(2)new keyword definition. For example:

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

4. Attributes of the object

Get the attribute value of the object:

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



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



obj.age = 20;
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)!


Statement:
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