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 Working with 'for' Loops The Refactor Challenge – One Solution

Anonymous User
PLUS
Anonymous User
Courses Plus Student 2,703 Points

Is there a reason we say 'let green;' or 'let randomRGB'? Is this another way of writing an empty string??

I'm a little confused by this. At the beginning of the script, where it says: let red; let green; let blue; let randomRGB;

Are these all ways of essentially just declaring empty strings? What is the purpose? Thats the only part that really threw me off in this section.

1 Answer

Steven Parker
Steven Parker
231,172 Points

These variables are being declared, but not assigned. They don't currently have any value, not even an empty string. They will get assigned later.

Declaring a variable defines its scope and makes it available for use in the program.

Okay , so why can't you just declare the variables inside the for loop? Can you explain this to me please?

Steven Parker
Steven Parker
231,172 Points

You could declare all but html inside the loop, but that would cause them to be created and then disposed for each pass. Declaring them just once allows them to be re-used in the loop passes.