Challenge - 5 Problems
Nested Objects Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
β Predict Output
intermediate2:00remaining
Accessing nested object properties
What is the output of the following code?
Javascript
const data = { user: { id: 101, profile: { name: "Alice", age: 30 } } }; console.log(data.user.profile.name);
Attempts:
2 left
π‘ Hint
Look at how to access properties inside nested objects using dot notation.
β Incorrect
The code accesses the 'name' property inside the 'profile' object, which is inside 'user'. The value is "Alice".
β Predict Output
intermediate2:00remaining
Modifying nested object values
What will be the output after running this code?
Javascript
const obj = { a: { b: { c: 5 } } }; obj.a.b.c = 10; console.log(obj.a.b.c);
Attempts:
2 left
π‘ Hint
Think about how assignment works on nested objects.
β Incorrect
The code changes the value of 'c' from 5 to 10, so logging it prints 10.
β Predict Output
advanced2:00remaining
Accessing nested object with optional chaining
What is the output of this code snippet?
Javascript
const user = { name: "Bob", address: { city: "New York" } }; console.log(user.address?.street);
Attempts:
2 left
π‘ Hint
Optional chaining returns undefined if the property does not exist.
β Incorrect
The 'street' property does not exist inside 'address', so optional chaining returns undefined without error.
β Predict Output
advanced2:00remaining
Deeply nested object property count
How many properties does the object 'data' have at the deepest level?
Javascript
const data = { level1: { level2: { level3: { a: 1, b: 2, c: 3 } } } }; console.log(Object.keys(data.level1.level2.level3).length);
Attempts:
2 left
π‘ Hint
Count the keys at the deepest nested object.
β Incorrect
The deepest object has keys 'a', 'b', and 'c', so the count is 3.
β Predict Output
expert2:00remaining
Merging nested objects with spread operator
What is the output of this code?
Javascript
const obj1 = { a: 1, b: { c: 2 } }; const obj2 = { b: { d: 3 }, e: 4 }; const merged = { ...obj1, ...obj2 }; console.log(merged.b.c);
Attempts:
2 left
π‘ Hint
Spread operator does a shallow merge, so nested objects get replaced, not merged.
β Incorrect
The 'b' property from obj2 replaces the one from obj1, so merged.b only has 'd', no 'c'. Accessing merged.b.c returns undefined.