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 )!