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 ; //优先考虑使用。但当属性字符串是常量,而且属性字符串是合法的标识符时,才能使用
var status = flight.status || “unkown”;
obj.age = 20;
Properties in the object prototype chain can also be accessed in the object.
delete operator can be used to delete attributes of an object.