0
var nyc = {
    fullName: "New York City",
    mayor: "Michael Bloomberg",
    population: 8000000,
    boroughs: 5
};

var myProperty = this.nyc;
/*this is one variable so how can it store all the values and what does this.nyc mean
and what value it carries, value of all property or just the value of one property*/
for(myProperty in nyc){console.log(nyc[myProperty]);}
//how is this line giving me the value of all the properties of object.

How does basically for in loop works?

1

1 Answer 1

1

myProperty is set to a new value at each iteration of the for loop. So the old value of myProperty does not matter.

Sign up to request clarification or add additional context in comments.

2 Comments

In fact, the assignment on top of the loop is redundant and highly confusing. A plain var myProperty; would have been better.
@Thilo: I agree. I think this is a symptom of his core confusion--he does not understand why, after assigning a particular property to myProperty it can still be used to enumerate all of them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.