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

Frank Sun
Frank Sun
3,155 Points

I think in the video "for in " loop is missing the keyword "var"! Why does the loop still work?

in the video call "Using for in to Loop Through an Object's Properties5:31 " JavaScript"

2 Answers

Actually Issac, that's incorrect. prop is not a predefined JavaScript keyword.

Frank, you're right. prop should have var before it. If it doesn't in the video, it's probably the case that it was either (1) defined at some other point in the document or (2) the instructor just forgot.

It will run without var though. JavaScript doesn't actually require you to use var to define variables. It's just best practice since if you don't use var, then the variable is defined in the global scope (behind the scenes) and this can cause problems.

Frank Sun
Frank Sun
3,155 Points

I see. Mikis, Thank you so much for your explanation, it helps me understand more about for in loop.

Isaac Calvo
Isaac Calvo
8,882 Points

thats why no documentation. thanks for explaining.

"JavaScript doesn't actually require you to use var to define variables."

thats good to know^^. blue = 1 returns 1 in mdn console.

Frank Sun
Frank Sun
3,155 Points

Thank you for your answer.