Introduction to Objects II 9/30


Here is my code:

var nyc = {
fullName: "New York City",
mayor: "Bill de Blasio",
population: 8000000,
boroughs: 5
for (var fullName in nyc){

It runs perfectly but i don't get the logic behind that.
Looking at the code, i would say that it only prints out fullName in nyc.
Or does for (var fullName in nyc)mean that it prints out all the propertys starting from fullName ?


When you use for loops, you're creating a new variable to be assigned as a 'placeholder' for each item inside an array/object.

For example:

for (var fullName in nyc) is saying "for each item in nyc, assign it the name 'fullName'"

Which indeed means that your console.log statement will print each item out in order, from fullName to boroughs.

It's the same as writing:

for (var x in nyc){