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
SAMUEL LAWRENCE
Courses Plus Student 8,447 PointsWhy didn't Dave use a 'var' keyword in his 'for in' loop?
Hi, in the video Dave McFarland , when using the for in loop, used the var keyword during his explanation, however when we were working with the for in loop he didn't. During the code challenge I also didn't use the var keyword, to which I got a bummer: It's a good idea to use thevarkeyword in afor inloop like this:for (var key in shanghai)`.
https://teamtreehouse.com/library/using-for-in-to-loop-through-an-objects-properties video time: 02:30
1 Answer
Steven Parker
243,656 PointsNot using the keyword causes an implicit global declaration, which is allowed (when not in "strict" mode) but not a "best practice". It was most likely omitted unintentionally in the video.
The challenge is specifically checking for "best practice" coding.
SAMUEL LAWRENCE
Courses Plus Student 8,447 PointsSAMUEL LAWRENCE
Courses Plus Student 8,447 PointsHi, Steven Parker you're awesome man. I completely forgot about
scope. Thanks for reminding me.