JavaScript has a Boolean data type and a boolean variable value is one that can either be TRUE or FALSE. The boolean function returns the boolean value of a variable.
- The boolean primitive type that has two values of
true
andfalse
. - The
Boolean
object is an object wrapper for a boolean value. - Use the
Boolean()
function to find out if an expression (or a variable) is true:
JavaScript boolean examples
Simple example code boolean primitive type. The following example declares two variables that hold boolean values of false
and true
:
<!DOCTYPE html>
<html>
<body>
<script>
let isPending = false;
let isDone = true;
console.log("isPending", isPending, typeof(isPending))
console.log("isDone", isDone, typeof(isDone))
</script>
</body>
</html>
Output:

Boolean object
Use the Boolean()
function to convert a string into a boolean value. Because the string is not empty, it returns true
.
let a = Boolean('Hi');
console.log(a); // true
console.log(typeof(a)); // boolean
The Boolean
is also a wrapper object of the boolean
primitive type. It means that when you pass either true
or false
to the Boolean
constructor, it’ll create a Boolean
object.
let b = new Boolean(false);
Operator | boolean | Boolean |
---|---|---|
typeof | boolean | object |
instanceof Boolean | false | true |
Do comment if you have any doubts or suggestions on this JS boolean topic.
Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.
OS: Windows 10
Code: HTML 5 Version

Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology & like learning technical.