Instead of brackets using dot notation


#1


https://www.codecademy.com/en/courses/objects-ii/1/5?curriculum_id=506324b3a7dffd00020bf661


Oops, try again. It looks like you didn't print the value of nyc's fullNameproperty


instead of this 
for(var end in nyc)
{
    console.log(nyc[end]);
    }
cant we write this ? 
for(var end in nyc)
{
    console.log(nyc.end);
    }


#2

@mananadun,
The so-called dot-notation access
only allows the literal property-key

=========================================

var james = {
    job: "programmer",
   married: false,
   sayJob: function() {
          // complete this method
          console.log("Hi, I work as a" + this.job);
    }
 };

Description of the james object.
The james object has 3 properties which are seperated by a comma-,

there is a job property with property-key job and it's associated string value 'programmer'
there is a married property with property-key married and it's associated boolean value false
there is a sayJob property with property-key sayJob and it's associated anonymous function VALUE
( they also would 'say', the james-object has the sayJob()-Method )

access via dot-notation

(no variable allowed, only literal property-key-name )
james.job ==> you will get the associated string VALUE of the job property-key, thus
you get the string VALUE 'programmer'

james.married ==> you will get the associated boolean VALUE false

james.sayJob ==> you will get the associated anonymous function VALUE
to call/execute this method you add a pair of parenthesis-( )
james.sayJob();

access via the square-bracket-notation

1 using the literal property-key

james["job"]
james["married"]
james["sayJob"]()

2 using the property-key by reference (=== via a variable )

var propertyKey1 = "job";
var propertyKey2 = "married";
var propertyKey3 = "sayJob";
james[propertyKey1] ==> you will get the associated string VALUE of the job property-key, thus
you get the string "programmer"

james[propertyKey2]
in this case you will get the boolean VALUE of the married property
being false

james[propertyKey3]();
would =display= "Hi, I work as a programmer"


#3

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