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

Luqman Shah
Luqman Shah
3,016 Points

What's the point of Boolean values if they have the same outcome as conditional statements?

Ok, so I know that he mentioned that this was a common way to keep track of a certain condition throughout a program, but why? Can't the same thing be achieved without these values? And why was the value placed in a variable in the first line of code:

var correctGuess = false;

var randomNumber = Math.floor(Math.random() * 6 ) + 1;

1 Answer

Zack Lee
PLUS
Zack Lee
Courses Plus Student 17,662 Points

a boolean is a fundamental value that defines a binary true or false. a conditional statement actually outputs a boolean value. it uses the boolean to determine if it is running or not. you can replace any statement in a conditional with simply a boolean. i.e.

if(true){
...
}

or

while(true){
...
}

you can also store a boolean value in a variable. this variable is basically just a boolean by another name.

var thisVariable = true;

if(thisVariable){
 //execute some code
}

booleans are very useful and theres is no simpler way to recreate their value. booleans are the heart of computers. all machine code is made up of 1's and 0's, which are binary values, equivalent to true or false, yes or no, on or off. bay far booleans are the most fundamental building block of all computer logic.