JavaScript Objects

Ariel Jakubowski
2 min readFeb 24, 2021

An object is a datatype that holds information in the form of key value pairs. A good way to think of an object and its key value pairs is like a drawer full of labelled folders. The drawer represents the object itself, the folders represent the object’s keys, and the information inside the folders are the values that pair with the keys.

Each of these folders would need a label to identify it, which in the case of our object would be the string or number used as an identifier in the object’s key. When strings are used in keys they can be written with or without quotes. The values that pair with can hold any sort of information.

The simplest JavaScript object possible is as follows.

{}

The code above is an empty JavaScript object. JavaScript objects are written using curly braces and contain a series of comma separated key value pairs. Objects can also be assigned to variables. If we waned to write an object to hold information about a pet we could do so as follows.

const myPet = {
name: 'Baby',
species: 'dog',
age: 9,
likes: ['fetch', 'snuggling', 'belly rubs']
}

Accessing Object Information

The values stored in an objects keys can be accessed with either dot or bracket notation, as shown below. An exception to this is when the keys…

--

--