Who's in your Bracket?


I understand the syntax and completed the instructions without error. My question is why does the variable aProperty work? In the line var aProperty = "job" , why does it not see "job" as a string? Thanks in advance.

var james = {
job: "programmer",
married: false

// set to the first property name of "james"
var aProperty = "job";

// print the value of the first property of "james"
// using the variable "aProperty"



I was having the same problem and I know the code is correct, so I went online and saw that if you refresh the page it will take it. I am not sure why this happens, but you should try it.


If i understood it correctly, when you tell it to log a variable with a bracket, it will look for that bracket it's refering too(Brackets are like tags in JavaScript, if i understood corretly). Please correct me asap if i am wrong, hehe.


Thank you. I confirmed this by removing the variable james and the brackets from the console.log and it returned the string job. So, that variable is just a string unless it's called properly. If you call:

console.log(aProperty) // Valid for returning "job"
console.log(james[aProperty]) // valid for returning a property of james called job.

Thank you again. I understand it now.


Thank you. In this case I almost wish it wasn't taking my code. LOL. When I submitted my code it worked perfect but I had no idea what I had just done.

I should have plowed on because a couple lessons later they actually explain how using brackets to call properties within objects works much better.

Thank you for your response!


How that happened !! when I have refreshed the page, the code have run although I wrote it correctly but it hasn't run. !?! :innocent: