JavaScript Objects

From Code Self Study Wiki
Jump to: navigation, search

This page contains notes about JavaScript objects.



Object values are by reference. If you copy an object into a new variable and change the new variable name, the old name will change too.


  • Configurable Attribute
  • Enumerable
  • Writable

Every object also has:

  • constructor
  • hasOwnProperty(propertyName)
  • isPrototypeOf(object)
  • propertyIsEnumerable(propertyName)
  • toLocaleString()
  • toString()
  • valueOf()

Creating Objects

Ways to create JavaScript objects:

Object Literals

var box = {
  color: "Green",
  width: 50,
  height: 50

Object Constructors

Use the new keyword.

var person = new Object(); = "John";
person.sayHello = function() {