Skip to content

Instantly share code, notes, and snippets.

@johnmmoss
Last active July 1, 2016 15:14
Show Gist options
  • Select an option

  • Save johnmmoss/300ded9067e9cd105efb8129cb36d15f to your computer and use it in GitHub Desktop.

Select an option

Save johnmmoss/300ded9067e9cd105efb8129cb36d15f to your computer and use it in GitHub Desktop.
Introduction to JavaScript
'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