JavaScript Objects: 15 Fundamentals You Should Know

Keys are strings, objects inherit from objects, class is sugar syntax, objects are hash maps, and more

Cristian Salcescu
DailyJS

--

Photo by the author

In this article, we will look at some of the most important concepts regarding objects in JavaScript.

1. The object literal is the simplest way to create objects

The simplest way to create an object is to use the object literal. We define a set of properties inside curly braces {} separated by commas. Below is an example.

const game = {
name: 'Fornite',
developer: 'Epic Games'
};

The previous object has two properties. The first property has the key name and the value Fornite.

2. Objects are dynamic collections of properties

Indeed object is a dynamic collection of props.

Once an object is created we can add, edit or delete properties from it. Below is an example of adding and deleting the year property to/from the previous game object.

game.year = 2017;
delete game.year;

3. Properties can be accessed using the dot and the bracket notations

--

--

Cristian Salcescu
DailyJS

Author of Functional Programming in JavaScript. Enthusiastic about sharing ideas. https://www.amazon.com/gp/product/B08X3TPCQ8