9.Getting IN-timate, someone explain why it works please


#1


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

for (var park in nyc) {
    console.log(park)
    }

#Hello, I have gone through this exercise pretty easily, but I still don't understand why the code works.
#There is no variable park in the object nyc, so why does it print every property when I call park?

#Here is a link of the exercise:

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

#If someone can, please explain it to me. Thanks in advance.


#2

the for in loop will in order/sequence assign property (fullName, mayor etc) to the loop iterator (park)

so park gets defined in the loop, the for in loop does most of the work for you


#3

Thanks. So it works like the i variable in the previous for exercises, I guess.


#4

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