Finished Chapter 5.1: Object Basics
parent
e0db7a67f0
commit
6c7d7a0ed2
|
@ -0,0 +1,15 @@
|
||||||
|
# Chapter 5: JavaScript Objects
|
||||||
|
|
||||||
|
## Object Basics
|
||||||
|
|
||||||
|
Create objects:
|
||||||
|
```js
|
||||||
|
let object_name = {
|
||||||
|
property_1_name: property1_value,
|
||||||
|
property_2_name: property2_value,
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
To access a single property, using `.` (dot) operator
|
||||||
|
|
||||||
|
Check code in [object-101.js](../src/objects/objects-101.js)
|
|
@ -0,0 +1,23 @@
|
||||||
|
// Model things from real world
|
||||||
|
|
||||||
|
let myBook = {
|
||||||
|
title: '1984',
|
||||||
|
author: 'George Orwell',
|
||||||
|
pageCount: 326
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(myBook) // { title: '1984', author: 'George Orwell', pageCount: 326 }
|
||||||
|
|
||||||
|
// Getting a single value
|
||||||
|
console.log(`Book Title: ${myBook.title}`);
|
||||||
|
|
||||||
|
// Challenge area
|
||||||
|
|
||||||
|
// name, age, location
|
||||||
|
let me = {
|
||||||
|
name: "Jason Zhu",
|
||||||
|
age: 27,
|
||||||
|
location: "Canberra"
|
||||||
|
}
|
||||||
|
// Andrew is 27 and lives in Philadelphia.
|
||||||
|
console.log(`${me.name} is ${me.age}, and live in ${me.location}`)
|
Loading…
Reference in New Issue