-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchap5.js
More file actions
30 lines (22 loc) · 671 Bytes
/
chap5.js
File metadata and controls
30 lines (22 loc) · 671 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// use new operator with the Object constructor
var person = new Object();
person.name = "Alan";
person.age = 10;
// use object literal notation
var person = {
name: "Alan",
age: 10
};
var person = {}; // same as: var person = new Object();
// use object literal notation to pass optional arguments to a function
function displayPerson(person) {
if person.name != undefined {;}
if person.age > 5 {;}
}
// use dot notation to access object properties, dot notation is more suggested
person.name;
// use bracket notation to access object properties
person["name"];
// useful to use vairables for property access
var propertyName = "name";
person[propertyName];