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 trialRyan Schmelter
9,710 PointsCan i create a variable, but not store anything in it until later in the program?
As an experiment, I wrote:
var correctGuess
without the value False at the top of the program and followed the rest of the steps in the video. The code still works. I'm wondering if this is acceptable practice to create a blank variable and then use it later?
1 Answer
Jennifer Nordell
Treehouse TeacherHi there! This is valid, but it sort of depends on what you're going to be using the variable for later. If it's going to be holding a string and you're sure of that, you should at least initialize it with an empty string. There can be unexpected consequences later on if you start trying to concatenate without having given it an initial value as the variable at that point is "Undefined".
Hope this helps!