Object - Bracket Notation

Hello,

I am a bit confused by the exercise here, if for step one:

let isActive = spaceship[‘Active Mission’];

why would one put propName while console.log? why don’t we put directly ‘Active Mission’? Thanks!

1 Like

I think it is part of the exercise.

Please be sure to include a link to the actual exercise page. Thanks.

1 Like

oh sorry i thought i did, but here it is ::

1 Like

I think @mtf meant that share a link to the codecademy exercise, and not to the github file like:
https://www.codecademy.com/courses/learn-python/lessons/python-lists-and-dictionaries?action=resume_content_item (python 2.7 lists lesson)

1 Like

Ah thanks! here it is :

https://www.codecademy.com/courses/introduction-to-javascript/lessons/objects/exercises/object-property-access-ii

1 Like

All object keys are strings.

for (key in spaceship) {
  console.log(typeof key);
}
string
string
string
string

That means we can store a property name (a key) and give it a variable name, which variable will point to a string.

With that string we can access a property of the object.

1 Like

thanks, but may i know why would we do that? why don’t we just put ‘Active Mission’ in the console.log? isn’t it one more step to do the same thing?

1 Like

Yes, it is but I think this one thing for the exercise that the learner should understand that it is possible to do.