Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
In JavaScript, objects are king: Almost everything is an object or acts like an object. Understand objects and you will understand JavaScript. So let’s examine the creation of objects in JavaScript.
An object is just a container for a collection of named values (a.k.a. properties). Before we look at any JavaScript code, let’s first reason this out. Take myself, for example. Using plain language, we can express in a table, a “cody”:
|
cody | |
|---|---|
|
property: |
property value: |
|
living |
true |
|
age |
33 |
|
gender |
male |
The word “cody” in the table above is just a label for the group of property names and corresponding values that make up exactly what a cody is. As you can see from the table, I am living, 33, and a male.