JavaScript Boolean() Constructor

The Boolean() constructor used to create a new Boolean object. The Boolean() constructor accepts one argument and produces a Boolean object, which holds a value of either true or false depending on the type and value of the argument passed in.

Syntax

Boolean(value)

Parameters

It accepts a single argument.

  1. Value: The value of the boolean object.

Example 1: How to Use JavaScript Boolean() Constructor

 let data1 = Boolean(true); 
 let data2 = Boolean(false); 

 console.log(data1); 
 console.log(data2); 

Output

true
false

Example 2: Using the Boolean Constructor to Convert String, Number, null and Date to Boolean Values

let data1 = Boolean("Welcome"); 
let data2 = Boolean("42");
let data3 = Boolean(123);
let data4 = Boolean(null);
let data5 = Boolean(new Date()); 

Output

true
true
true
false
true

Browser Compatibility

Chrome Edge Firefox Safari Opera IE
Yes Yes Yes Yes Yes Yes

That’s it!

Related posts

JavaScript Boolean valueOf()

JavaScript Boolean toString()

Leave a Comment