Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Challenge: Accessing Object Properties | Objects Fundamentals
JavaScript Data Structures
course content

Course Content

JavaScript Data Structures

JavaScript Data Structures

1. Introduction and Prerequisites
2. Objects Fundamentals
3. Advanced Object Manipulation
4. Mastering Arrays
5. Advanced Array Operations

book
Challenge: Accessing Object Properties

Task

You're given an object, user, representing a person's hobbies and interests. Your task is to access and retrieve specific details from the object.

  • Access and log the person's name.
  • Access the indoor hobby and log it to the console.
  • Store the person's age in a variable.
  • Access the favorite music genre and log it.
12345678910111213141516171819202122232425
const user = { name: "Sarah", age: 32, hobbies: { outdoor: "hiking", indoor: "painting", }, preferences: { music: "jazz", movieGenre: "sci-fi", }, }; // Task 1 console.log(___); // person's name // Task 2 console.log(___); // indoor hobby // Task 3 const userAge = ___; console.log(userAge); // person's age // Task 4 console.log(___); // music genre
copy

Expected output:

  1. Use dot notation to access properties within an object.
  2. To access properties within nested objects and arrays, chain the dot notation and square brackets (if needed).
  3. Use assignment with dot notation to store property values in variables.
123456789101112131415161718192021222324
const user = { name: "Sarah", age: 32, hobbies: { outdoor: "hiking", indoor: "painting", }, preferences: { music: "jazz", movieGenre: "sci-fi", }, }; // Task 1 console.log(user.name); // person's name // Task 2 console.log(user.hobbies.indoor); // indoor hobby // Task 3 const userAge = user.age; console.log(userAge); // person's age // Task 4 console.log(user.preferences.music); // music genre
copy

Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 2. Chapter 6
We're sorry to hear that something went wrong. What happened?
some-alt