Challenge - 5 Problems
Object Property 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 user = { name: 'Alice', details: { age: 30, city: 'Paris' } }; console.log(user.details.city);
Attempts:
2 left
π‘ Hint
Think about how to access properties inside nested objects using dot notation.
β Incorrect
The property 'city' is inside the 'details' object. Accessing user.details.city returns the string 'Paris'.
β Predict Output
intermediate2:00remaining
Accessing object properties with bracket notation
What will this code output?
Javascript
const obj = { 'first-name': 'John', age: 25 }; console.log(obj['first-name']);
Attempts:
2 left
π‘ Hint
Use bracket notation to access properties with special characters or hyphens.
β Incorrect
Since 'first-name' contains a hyphen, it must be accessed with bracket notation. obj['first-name'] returns 'John'.
β Predict Output
advanced2:00remaining
Accessing properties with variables
What is the output of this code?
Javascript
const key = 'score'; const player = { name: 'Bob', score: 42 }; console.log(player[key]);
Attempts:
2 left
π‘ Hint
When using a variable to access a property, use bracket notation.
β Incorrect
player[key] accesses the property named 'score' because key holds the string 'score'. The value is 42.
β Predict Output
advanced2:00remaining
Optional chaining with object properties
What will this code output?
Javascript
const data = { user: { profile: { name: 'Eve' } } }; console.log(data.user?.profile?.age);
Attempts:
2 left
π‘ Hint
Optional chaining returns undefined if a property does not exist instead of throwing an error.
β Incorrect
The property 'age' does not exist inside profile, so data.user?.profile?.age returns undefined safely.
β Predict Output
expert3:00remaining
Dynamic property access and computed property names
What is the output of this code?
Javascript
const prefix = 'user'; const id = 7; const obj = { [`${prefix}${id}`]: 'active' }; console.log(obj.user7);
Attempts:
2 left
π‘ Hint
Computed property names allow dynamic keys in object literals.
β Incorrect
The key is computed as 'user7', so obj.user7 returns 'active'.