JavaScript booleans are a primitive data type that has either true
or false
values. It is mainly used in conditional statements such as if
, if..else
, switch
, etc.
Source Code
var isDeveloper = true;
var isDesigner = false;
The Boolean() constructor function is basically used to take input and convert it into a boolean value. It can also evaluate the javascript expression and provides results into a boolean value.
Let us understand it with the help of an example.
Source Code
var isDeveloper = true;
var isDesigner = false;
When the Boolean()
constructor function is invoked by a new
operator then it generates new instances of the boolean object.
Source Code
var isDeveloper = true; // boolean
var isDba = new Boolean(true); // object