5. Why use string and not dot notation?



The code works fine!

I wanted to know why instead of

var aProperty = james.job;

just a string called "job" is required.

I don't understand why just a string of "job" links back to the property that is james.job. I thought "job" would just be "job".

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"


The point that they seem to try to make is that the key can be a value, doesn't have to be written in the code. That means it can be obtained from input, generated during runtime, randomised etc


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