Recall & Review
beginner
What is a nested object in JavaScript?
A nested object is an object that is a value inside another object. It means one object contains another object as a property.
Click to reveal answer
beginner
How do you access a property inside a nested object?
You use dot notation or bracket notation for each level. For example,
obj.innerObj.property accesses property inside innerObj which is inside obj.Click to reveal answer
beginner
Given <code>const person = { name: 'Anna', address: { city: 'Paris', zip: 75000 } };</code>, how do you get the city?You get the city by writing
person.address.city. This goes inside the address object to get the city property.Click to reveal answer
intermediate
Can nested objects contain arrays or other nested objects?
Yes! Nested objects can have arrays or even more objects inside them. This lets you build complex data structures.
Click to reveal answer
intermediate
How do you safely access a deeply nested property without errors if some parts might be missing?
You can use optional chaining like
obj?.innerObj?.property. This stops and returns undefined if any part is missing, avoiding errors.Click to reveal answer
What does the following code access?<br>
user.profile.email✗ Incorrect
Dot notation reads from left to right: user → profile → email property.
Which is the correct way to access the zip code in this object?<br>
const data = { location: { zip: 12345 } };✗ Incorrect
The zip code is inside the location object, so use data.location.zip.
What will
obj?.inner?.value return if obj.inner is undefined?✗ Incorrect
Optional chaining returns undefined if any part before it is missing, avoiding errors.
Can a nested object property be an array?
✗ Incorrect
Objects can have any type as property values, including arrays.
How do you add a new nested object property to an existing object?
✗ Incorrect
You can add nested properties anytime by assigning an object to a property.
Explain what a nested object is and how you access its properties in JavaScript.
Think about objects inside objects and how to reach inside.
You got /4 concepts.
Describe how optional chaining helps when working with nested objects.
It uses question marks to safely check each level.
You got /4 concepts.