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, Arrays and Objects Simplify Repetitive Tasks with Loops Exiting Loops

Andrea Boscolo
Andrea Boscolo
7,250 Points

In the IF at the end why I don't need do specify correctGuess === true;?

In the IF at the end why I don't need do specify correctGuess === true;?

2 Answers

andren
andren
28,558 Points

Because conditional statements like if runs based on whether the value they are given evaluates to the Boolean true.

When you compare two values that comparison actually produces a Boolean value. true if the comparison is correct and false if it isn't. That means that the comparison correctGuess === true would actually produce the boolean true if correctGuess stored true and false if it stored false.

So comparing correctGuess to true would result in the exact same value that is already stored within it. Making the comparison pointless.

Andrea Boscolo
Andrea Boscolo
7,250 Points

Thanks! your explanations are always great!