10. list ALL the Properties!



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) {


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.


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