Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Basics (Retired) Making Decisions with Conditional Statements Boolean Values

Ryan Schmelter
Ryan Schmelter
9,710 Points

Can 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
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi 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! :sparkles: