JavaScript Objects: 15 Fundamentals You Should Know
Keys are strings, objects inherit from objects, class is sugar syntax, objects are hash maps, and more
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;