diff --git a/notes/chapter5_javascript-objects.md b/notes/chapter5_javascript-objects.md new file mode 100644 index 0000000..f2011f3 --- /dev/null +++ b/notes/chapter5_javascript-objects.md @@ -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) \ No newline at end of file diff --git a/src/objects/objects-101.js b/src/objects/objects-101.js new file mode 100644 index 0000000..1f554d6 --- /dev/null +++ b/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}`) \ No newline at end of file