A JavaScript Boolean represents one of two values: true or false.
Very often, in programming, you will need a data type that can only have one of two values, like
For this, JavaScript has a Boolean data type. It can only take the values true or false.
You can use the Boolean() function to find out if an expression (or a variable) is true:
Or even easier:
The chapter JS comparisons gives a full overview of comparison operators.
The chapter JS conditions gives a full overview of conditional statements.
Here are some examples:
Operator | Description | Example |
---|---|---|
== | equal to | if (day == "Monday") |
> | greater than | if (salary > 9000) |
< | less than | if (age < 18) |
![]() |
The Boolean value of an expression is the fundament for JavaScript comparisons and conditions. |
---|
Primitive values, like true and false, cannot have properties or methods (because they are not objects).
But with JavaScript, methods and properties are also available to primitive values, because JavaScript treats primitive values as objects when executing methods and properties.
For a complete reference, go to our Complete JavaScript Boolean Reference.
The reference contains descriptions and examples of all Boolean properties and methods.