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 Basics (Retired) Making Decisions with Conditional Statements Boolean Values

true false

you didn't write anything in if statement for example

if (guesscorrect) {bla bla boa}, but I expected you write some comparison or smith like that element as we did previous codes for example if (guesscorrect==="smth") {boa bla bla}

1 Answer

David Clausen
David Clausen
11,403 Points

Well if only execute if something is true.

In java-script anything non zero is considered true.

So if guesscorrect = true then an if statement will run, if guesscorrect > 0 then an if statement will run

var guesscorrect = true;
if (guesscorrect )
return

So you can see he is evulating if guesscorrect is true. Now you can obviously be specific and check if something is false if(guesscorrect == false) again if guesscorrect is false then the if statement comparison is true.

Stephen Perez
Stephen Perez
4,229 Points

Hola! I wanted to supplement David's answer: David wrote "In java-script anything non zero is considered true."

I don't believe this is fully correct. Falsey values include: 0, false, null, undefined, NaN, and "" while all other values evaluate to true. Zat is all!