0
0
Javascriptprogramming~20 mins

Nested objects in Javascript - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
πŸŽ–οΈ
Nested Objects 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 data = {
  user: {
    id: 101,
    profile: {
      name: "Alice",
      age: 30
    }
  }
};

console.log(data.user.profile.name);
Aundefined
B"Alice"
Cnull
DTypeError
Attempts:
2 left
πŸ’‘ Hint
Look at how to access properties inside nested objects using dot notation.
❓ Predict Output
intermediate
2: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);
A10
Bundefined
C5
DTypeError
Attempts:
2 left
πŸ’‘ Hint
Think about how assignment works on nested objects.
❓ Predict Output
advanced
2: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);
Anull
BTypeError
C"" (empty string)
Dundefined
Attempts:
2 left
πŸ’‘ Hint
Optional chaining returns undefined if the property does not exist.
❓ Predict Output
advanced
2: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);
A0
B1
C3
DTypeError
Attempts:
2 left
πŸ’‘ Hint
Count the keys at the deepest nested object.
❓ Predict Output
expert
2: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);
Aundefined
B3
C2
DTypeError
Attempts:
2 left
πŸ’‘ Hint
Spread operator does a shallow merge, so nested objects get replaced, not merged.