Objects Introduction

Now you are ready to learn about JavaScript Objects.


What are objects?


As you may remember from the previous course, Variables are described as “containers” of a value ( string, number etc).

As you may remember Arrays are used to store multiple values in a single variable.

In the same way, Objects are variables themselves who act as containers for many variables.

The way objects are defined is:

var myObject = { 
name:"myName",
age:20,
job:"myJob"
};

The rules for the above syntax are:

  • The object is contained within curly braces.
  • The values are written as name : value pairs. In the above example, for the value age:”myAge”, the age is the name and the 20 is the value.
  • The name:value pairs are called properties
  • Names and values are separated by a colon
  • Each name:value pair, is separated from the others by commas