Nested objects are objects that are stored as values within other objects. This means that we can have an object property that itself is an object. This nesting can be performed to any depth, creating a hierarchical structure of objects.
To create a nested object, we simply assign an object as a value to a property within another object. This can be done during the object's initialization or later by assigning a new object to an existing object property.
To access properties within a nested object, we use dot notation or bracket notation multiple times, chaining along the properties of each level.
We can modify the properties of a nested object by simply accessing them and assigning a new value.
Access the value of the
city property in the
address object and console.log it.
Add a new property
zipCode with the value "10001" to the
person object to see the updated values.
Sign up to start coding
Already have an account?