I have some questions in quiz, after passing lesson 'objects'

Good day. I do not understand why some options are correct in the quiz. https://www.codecademy.com/paths/web-development/tracks/web-dev-js-arrays-loops-objects/modules/learn-javascript-objects/quizzes/learn-javascript-objects-objects-quiz,

Why is the third option is correct answer? If this is correct, it means that we can use other three forms of calling _num. Why do we can use console.log(tempObj[‘num’])? I see this form of calling first time. Why do we use square brackets here?

Why the last option is true? What is it, ‘js’?
I thought the third option was true. It is not a correct object literal?!

And why is the last option true? Why we use square brackets again? I thought we could write bikes.specialized = ‘red’?

I will be very appreciative to see your explanations

1 Like

this is true. We can use these three forms.

the square brackets is known as associative array notation, in JS objects are associative arrays (and vice versa)

this notation is useful if you have a string (which could come for user input for example) or you have a property with a space in the name (then you have to use associative array notation, you can’t use the dot notation)

after a property (greeting) there should be a colon, not an equal sign.

however, the last option is not displaying correctly (which is why i can understand you are confused), the js bit is from codecademy, indicating the syntax is Javascript, normally this shouldn’t be displayed, i will report it.

hopefully i explained square brackets earlier

we can, except in the answer you see let at the beginning of the line, when adding to an existing object, let shouldn’t be used (let should only be used when declaring variables)


Hm, now its better, but now I cannot understand why it is correct to use quotes in the last answer. We use quotes when we have a space between the words, or special characters, isn’t it?

when using the associative array notation, you have to use a string. The associative array notation can always be used, you have to use it when dealing with spaces in your key/property.

there is a difference between can and have to :wink:

1 Like

This topic was automatically closed 18 hours after the last reply. New replies are no longer allowed.