Until now we saw the JavaScript primitive types. They can hold one and just one value associated with them.

Objects are different.

An object is defined using different syntaxes. The simplest one is the object literal:

const car = {}

You can also initialize an object using the Object() global function:

const car = Object({
  color: 'blue'

The object literal is the simplest syntax.

An object is a collection of properties. Every property can be defined at initialization time, and later retrieved using the dot notation:

const car = {
  color: 'blue'

car.color //blue

A property has a name, and a value.

A value can be a function, in which case we don’t call it a property, but instead we call it a method.

const car = {
  drive: function() {
    //do something

We can “see” it using car.drive, and we can invoke (run) it by appending the parentheses: car.drive().


More on functions later.

Go to the next lesson