0
0
Javascriptprogramming~20 mins

Accessing object properties in Javascript - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
πŸŽ–οΈ
Object Property Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2: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);
A"Paris"
B"city"
Cundefined
DTypeError
Attempts:
2 left
πŸ’‘ Hint
Think about how to access properties inside nested objects using dot notation.
❓ Predict Output
intermediate
2: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']);
A"first-name"
Bundefined
C"John"
DSyntaxError
Attempts:
2 left
πŸ’‘ Hint
Use bracket notation to access properties with special characters or hyphens.
❓ Predict Output
advanced
2: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]);
A"score"
B42
Cundefined
DReferenceError
Attempts:
2 left
πŸ’‘ Hint
When using a variable to access a property, use bracket notation.
❓ Predict Output
advanced
2:00remaining
Optional chaining with object properties
What will this code output?
Javascript
const data = { user: { profile: { name: 'Eve' } } };
console.log(data.user?.profile?.age);
A"age"
Bnull
CTypeError
Dundefined
Attempts:
2 left
πŸ’‘ Hint
Optional chaining returns undefined if a property does not exist instead of throwing an error.
❓ Predict Output
expert
3: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);
A"active"
BSyntaxError
Cundefined
DTypeError
Attempts:
2 left
πŸ’‘ Hint
Computed property names allow dynamic keys in object literals.