Object Initializers part2

JavaScript Tutorial
Objects
Object Initialization
83
2/2
         

Using Object Initializers



Spaces and line breaks are not important. An object definition can span multiple lines.var John = {
name: "John",
age: 25
};
var James = {
name: "James",
age: 21
};

No matter how the object is created, the syntax for accessing the properties and methods does not change.
document.write(John.age);
//Outputs 25
Try It Yourself

Don't forget about the second accessing syntax: John['age'].

Comments

Popular posts from this blog

String Operators

Introducing object part 3

The math object part 2