10. list ALL the Properties!


#1


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


var nyc = {
fullName: "New York City",
mayor: "Bill de Blasio",
population: 8000000,
boroughs: 5
};
After playing around for a bit I've found that setting the variable to anything works, including numbers and booleans, to output values; and the same for properties. Is this just a default syntax for javascript and I should accept it, or is there something else going on here that I don't understand?

// write a for-in loop to print the value of nyc's properties
var value = "value"; // changing "value" to true, or 3 also works
for (var value in nyc) {
console.log(nyc[value]); //is it that as long as this syntax exists it'll output the values?
}
//for the previous exercise to list all properties
for (var key in nyc) {
console.log(key);
}



#2

Sorry for the late reply.

Pretty much you can set the variable to anything when looping through the properties of an object.

I think it's the default syntax for JS, though I'm not exactly sure why it doesn't affect what happens inside the for-in loop.


#3

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