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

still wrapping my head around why we dont have to test if( correctGuess === true) { ...}

why we can delete the evaluation of the boolean variable... such as if ( correctGuess ){..} and it still only follow this iteration when true.

if each answer to these questions is a YES then i get it , if not then no idea..

is the true state the always the first test? if I wanted to test for false first would have to write if ( correctGuess !=== true){..}
does true mean exist in a way?

5 Answers

is the true state the always the first test?

Exactly. When you use an if statement to test a boolean, its default behavior is to check if the value is true. You only need to use "!", "!=" etc if you want to override that and check for false instead.

// this is the same as saying if (correctGuess == true)
if (correctGuess) {
  // do something
}

// if you want to test for 'false'
if (correctGuess == false) {
  // do something 
}

// or like this
if (correctGuess != true) {
  // do something
}

// and this is like saying if (correctGuess == false) too
if (!correctGuess) {
  // do something
}

You're amazing; that's totally cleared it up!

Thanks for the answers I had the same question haha

Thank you both for your answers.

Thanks. I did not quite catch how correctGuess by itself within the conditional statement was checking to see if it was true. Thanks for clearing it up.