Essential JavaScript

Making Objects

It's easy to create your own objects.

To create an empty object, simply assign a pair of curly braces to a variable:

const person = {};

This will give us an object with no properties.

To give an object properties, put them between the curly braces. Property names look like variable names - they should be in camel case:

const person = {
  firstName: 'John',
  lastName: 'Doe',
  age: 22,
  likesSpicyFood: true,

Now our object has four properties: firstName, lastName, age, and likesSpicyFood.

Both firstName and lastName are strings, age is a number, and likesSpicyFood is Boolean.

Object properties can be any type.

Learning Goals

Code Editor