Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Object-Oriented JavaScript Object Basics Dot Notation & Bracket Notation

Mihai Childesco
Mihai Childesco
9,326 Points

i didnt understand that var prop = 'beer' ernie[prop] how did the var prop transfered in the object ernie ?

i didnt understand that

julian Ellis
julian Ellis
3,542 Points

I too am struggling with this

Steven Parker
Steven Parker
231,275 Points

julian, try starting a fresh question, and be a bit more explicit about what you're having trouble with.

2 Answers

Christian van Lierop
Christian van Lierop
13,758 Points

I understand your confusion. Let me tyry to explain:

  • The property 'breed' is already declared in the object 'ernie'
  • now you create a variable called 'prop' with a string value of 'breed'
  • instead of calling the method as ernie['breed'] you can now also call it using ernie[prop] because the variable prop is equal to the string 'breed' (prop = 'breed')

Hope this clarifies it a bit.

Steven Parker
Steven Parker
231,275 Points

Did you try out the examples yourself? A bit of experimentation might be much more valuable than additional explanations.

And the property in the example was "breed". We probably should not give ernie any "beer", he's only 1 year old! :wink: