Objects differ from the other (primitive) datatypes of JavaScript(Number, String, Boolean, null, undefined, and symbol) in the sense that it’s more complex. The aforementioned data types store single values, while objects can contain many combinations of these primitive data types.
GET THE JOKE? You tell ’em, Mr. Morris.
Let’s use the following object as an example to explain some key features of the Object.
In the example above, things like name, breed, and status, or as well define them now as ‘keys’, point to values of ‘Ein’, ‘Pembroke Welsh Corgi’, and ‘Genius’, respectively. Properties of an object is a combination of these ‘key: value’ pairs. In this case, the dog object has three properties. One other thing to note is that keys can be either strings or numbers.
I hope you get the reference!
An object can also have a function as it’s member, so it’ll be referred to as an object’s method.
3. Constructors via Object-Oriented Programming methods
ES6 introduced the more traditional way of defining objects the way other programming languages (like Java or Ruby) do. Keep in mind that while the original javascript wasn’t built for OOP, over time, especially now more than ever due to high usage, it supports it.
Keep in mind, a number can be a key for an object. If you want to access a value that has a number key, you need bracket notation to access it.
Use Cases
Objects are useful for storing relations between strings and data. With the dog examples above, we are able to store a lot of data that are related together in one place. One practical way to use them is through lookup tables or dictionaries. Think of the game Scrabble. Each letter has its own point value. Common letters, like A, E, or R, are worth one point. Other letters, like the dastardly Q, are worth 10. You can think of it like this: