Finished Chapter 5.1: Object Basics

master
Jason Zhu 2021-01-19 21:40:05 +11:00
parent e0db7a67f0
commit 6c7d7a0ed2
2 changed files with 38 additions and 0 deletions

View File

@ -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)

View File

@ -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}`)