1.Define an Object
1 | //define an empty object |
It is not necessary to surround properties with quote if property name is a legal javascript name. For example: quotes are necessary for user-name but optinal for userName.
Legal javascript name: contains letters(upper case or lower case), digitals, _ and $ , but should not begin with digital
Object can nest:
1 | var user = { |
2.Object Property values
1 | //access by [] or . |
Update property value. if property name was defined, value will be replaced by the new value. if there is no such property, a new property will be added to this Object.
1
2user.userName = "yulong"; //value of userName is updated
user.child = {}; //new property child is added
Retrieve value by for in loop.
1 | for(var key in user) { |
3.Object passed by reference and can not be copied
1 | var user2 = user; |