A boolean variable is used to identify whether a condition is true or false.
Accordingly, boolean values can only assume two values:
Here is an example of how to create a boolean variable with a value of
let exampleBoolean = true;
Similarly, here is an example of how to create a boolean variable with a value of
let anotherExample = false;
Notice how I used the
let keyword when creating these two variables, and not my normal default
Said differently, boolean variables are designed to be toggled to change the functionality of your applications.
We will learn how to do this in our next lesson, when we learn about how to write
false depending on whether some mathematical condition is met.
<: less than
>: greater than
<=: less than or equal to
>=: greater than or equal to
Here are a few examples of how you can use comparison operators to generate
5 < 6;
5 > 6;
5 <= 6;
5 >= 5;
== operator and using the
=== operator. Here are two examples:
const value = 30;
value === 30;
value == 30;
value === 40;
value == 60;
You are probably wondering what the difference is between the
=== equality operators.
=== operator checks for equality between both value and type. The
== operator only checks for the equality of value.
Here is an example so you can see this concept in action:
10 == '10';
//Returns true, since their value is the same but their type is not
10 === '10'
//Returns false, since their value is the same but their type is not
In practice, you should almost always use the
Here is a summary of the topics we covered:
- The two values that can be assigned to a boolean variable