// ch25 Object and properties
- object literal: the way of define the object
var john = {
firstName: "John",
//key: value
lastName: "Smith",
birthYear: 1990,
family: ["jane", "Mark", "Bob"],
job: "teacher",
isMarried: false
};
console.log(john.firstName);//:'firstName' is a property of the 'Object john'.
console.log(john["lastName"]);
var x = "birthYear";
console.log(john[x]);
- mutation of the object
john.job = "designer";
john["isMarried"] = true;
console.log(john) //print
/*
firstName: "John"
lastName: "Smith"
birthYear: 1990
family: (3) ["jane", "Mark", "Bob"]
job: "designer"
isMarried: true
*/
- new object syntax
var jane = new Object();
jane.firstName = "Jane";
jane.birthYear = 1978;
jane["lastName"] = "Smith";
console.log(jane);
'javascript' 카테고리의 다른 글
JavaScript/ Loops and Iteration (0) | 2020.02.13 |
---|---|
JavaScript/ Objects and Methods (0) | 2020.02.13 |
JavaScript/ Array Basic (0) | 2020.02.13 |
JavaScript/ Function Basic (0) | 2020.02.13 |
JavaScript/ Basic (0) | 2020.02.13 |