Nested Object Access
Predict Output Medium
Question
What does this code print?
Code
let o = {a: {b: {c: 5}}};
console.log(o.a.b.c);
Hint
Chain of property accesses.
Explanation
o.a is {b: {c: 5}}, o.a.b is {c: 5}, and o.a.b.c is 5. Optional chaining o?.a?.b?.c would also give 5 but safely return undefined if any intermediate property is null/undefined.
Related Resources
Related Lessons
- Objects
Learn JS objects.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.