Essential JavaScript

Going Further

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

  • I can defined an object and assign it to a variable

  • I can give an object properties that are any type

Code Editor

Click "Run Code" to execute your JavaScript in a secure sandbox and see the output below.

Console Output

// Console output will appear here...

0 output lines