Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

maybe just confusion

Not really a question, but a complaint... Why does Dave teach use "for (prop in person) " but yet the quiz let and his opening rant clearly state to use "for (var prop in person) " . Can someone answer for the lack in consistency in the teaching and quizlet???

1 Answer

Hi there! The structure of the for/in loop is:

for(var prop in property)

I don't remember the video that you are talking about but I'm sure that Dave had declared the prop variable before the for/in loop, aka:

var prop;
for(prop in property)

You need to declare the variable but there is no matter where are you going to do it, before the loop or inside it. I think it's best to do it inside the loop, because you are only using that variable in the that perticular loop and if you are writing a big program with lots of code, you are going to mess up with the scope of the variables.

Ok, I was a bit frustrated but that makes sense..

thank you much