Last active
July 1, 2016 15:14
-
-
Save johnmmoss/300ded9067e9cd105efb8129cb36d15f to your computer and use it in GitHub Desktop.
Introduction to JavaScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 'use strict' | |
| // An empty JavaScript object | |
| var myEmpty = {}; | |
| // Create an object using object literals | |
| var monkey = { name: "John", age: 23, color: "blue" }; | |
| console.log(monkey.name) // John | |
| // You don't actually need to declare a property for it to be there: | |
| monkey.height = 200; | |
| console.log(monkey.height) // 200 | |
| // A property can also be a function | |
| var gorilla = { name: "ted", age: 42, color:function() { return "orange" } }; | |
| console.log(gorilla.color()) // orange | |
| // we can create new objects using a constructor function | |
| function Monkey(name, color) { | |
| this.name = name; | |
| this.color = color | |
| } | |
| var bill = new Monkey("bill", "pink"); | |
| // bill is a new object | |
| console.log(bill.color); // pink |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment