FAQ: Objects - Bracket Notation


#1

This community-built FAQ covers the “Bracket Notation” exercise from the lesson “Objects”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Web Development

Introduction To JavaScript

FAQs on the exercise Bracket Notation

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!


#2

Hey there! I just ran the following snippet

`let propName =  'Active Mission';
console.log(spaceship.propName)

and it returned undefined. How is it possible like the propName and ‘Active Mission’ both point to the same location right?


#3

propName is just a variable, the code you provided it doesn’t like propName a property of an object.


#4

Hi Everyone,

I was facing difficulty with understanding what instruction #2 was asking. It may be silly but as a novice, sometimes I tend to overthink the instructions. After trial and error and re-reading the instruction over and over, I came up with the code that gave me the result: “Active Mission true”

Instruction summary:

  1. Its asks to use bracket notation AND the propName variable
  2. log the value of ‘Active Mission’ property

My thought process:

  1. the value of the variable propName is a string: ‘Active Mission’
  2. ‘Active Mission’ is only a property with a value, in the spaceship object
  3. I have to locate both the string value and the property value, and log them together

CODE RESULT:

let propName = ‘Active Mission’
console.log(propName, spaceship[‘Active Mission’]);

I received the green checkmark on this. However, I would like to know if I understood the exercise correctly and if the code result is what was needed.

Thank you!


#5

Hi,
I agree. The instructions for #2 are confusing.
I just wrote:
console.log(spaceship[‘Active Mission’]); //output: true

And then I got a green checkmark for that task.
I then checked the hints, as I thought I was missing out something about the propName variable, but the hint just said: console.log(objectName[variableName])
…which looks like it’s what I did. So… Why is the propName variable even there?

/grumsen


#6

you could have used propName (which is a variable) instead of hard-coding the string when accesing spaceship


#7

Ah… I think what confuses me is that the propName is just a variable. It’s not pulling anything from the object and I can’t use bracket notation on the variable alone. If it was pulling the property from the object it would mabye make more sense.

But you’re saying that the correct answer should be:
console.log(spaceship[propName]);

Thanks. Makes sense for me now. :slight_smile:


#8

yes, its indeed just a variable with a string value.

that is indeed the answer the lesson is after