JavaScript Booleans - Learn Booleans in JavaScript
JavaScript Booleans
- A JavaScript Boolean contains two values: true or false.
Boolean Values
In programming, you will frequently require a data type that can only hold one of two values, such as
- YES / NO
- ON / OFF
- TRUE / FALSE
For this, JavaScript has a Boolean data type. It can only take the values true or false.
The Boolean() Function
- You can use the Boolean() function to find out if an expression (or a variable) is true.
Sample Code
Output
Conditions and Comparisons
Operator | Description | Example |
---|---|---|
== | equal to | if (day == "Monday") |
> | greater than | if (salary > 9000) |
< | less than | if (age < 18) |