Accessing object properties one
How to solve it
But, the value of an object property could have any value, for example a number or even another object that has even more properties.
There are two distinct ways to access a property value of an object with a key. The first one is by using the dot notation. Simply write down the object name and the key of the requested property, separated by a dot:
const obj = { x: 1 };
console.log(obj.x);
// output: 1
The other way to access an object property is using the square bracket notation. Instead of using a dot, type the key in string format encapsulated by square brackets:
const obj = { x: 1 };
console.log(obj['x']);
// output: 1
We will learn about the differences between the two approaches in this challenge.
Objects vs. arrays:
This way of accessing values within objects is very different from how you would access values within arrays. In order to get a specific array value, you have to know exactly at which position it is located (see this challenge for a comparison). Also, if the array value was removed in the meantime, you might get the wrong value. But, if an object property was removed before accessing it, you will know that it does not exist because you get undefined.