Object Access
Predict Output Beginner
Question
What does this code print?
Code
let o = {x: 5};
console.log(o.x + o["x"]);
Hint
Both dot and bracket access the same property.
Explanation
o.x is 5 and o["x"] is also 5. They are equivalent ways to access the same property. The sum is 5 + 5 = 10.
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.