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 JavaScript Loops, Arrays and Objects Tracking Data Using Objects Review Loops, Arrays, and Objects

Georg Günter
Georg Günter
5,150 Points

The Loop in the final Quiz in "JavasCript Loops, Arrays and Objects" is probably wrong.

In the final Quiz of the "JavaScript Loop, Arrays and Objects" Track is a Question with a for Loop where the variabel declaration "var" for the statement is missing.

It looks like "for(property in somearray) {...}" but shouldn't it be "for(var property in somearray) {...}".

Your right. You should e-mail treehouse with a snapshot of you screen telling them that the quiz is wrong.

1 Answer

Steven Parker
Steven Parker
230,248 Points

This is an issue of variable scope. Just like when you make an assignment, you can use var or not:

foo = 3;      // this creates variable foo with global scope
var foo = 2;  // this creates foo with local scope

If you were not inside a function, there would be no difference.

So, in the case of the loop, a variable is created for identify the index of the iteration:

for(property in somearray) {...}      // property is global
for(var property in somearray) {...}  // property is local

There's nothing in the quiz example to indicate what the scope actually is, or if a difference would be significant.