How come it Prints all property values , when only one is assinged


#1


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


how come it prints all object property values when we set only one property name in var x at line 9 i.e. var x="fullName" and still it prints all value of nyc object


var nyc = {
    fullName: "New York City",
    mayor: "Bill de Blasio",
    population: 8000000,
    boroughs: 5
};

// write a for-in loop to print the value of nyc's properties
var x= "fullName";
for(var x in nyc){
console.log(nyc[x]);
}


#2

I dont can explain it better than the Mozilla Developer Network

So read pleas this here

And you will get a Idea how a for ... in loop works


#3

Got it.thanks for the reply.


#4

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