Objects in JavaScript
Now it is time to have a look at another complex data structure that can contain more than one value: objects! Objects are very useful and can be used to describe real-life objects as well as more complex abstract concepts that allow for more flexibility in your code.
Secretly, you have just been introduced to objects already, because arrays are a very special type of object. Arrays are objects with indexed properties. All the other objects, and also the objects we will see here, are objects with named properties. This means that instead of an automatically generated index number, we will give it a custom descriptive name.
As we can tell from the following code, arrays are defined by JavaScript as being of the object type:
let arr = [0, 1, 2];
console.log(typeof arr);
The output of the preceding code is as follows:
Object
Objects are not too dissimilar to real-world objects. They have properties and they can perform actions, methods...