---
title: "Boolean Object in JavaScript"  
description: "Introduction:  Boolean objects represent either of the two values, true or false. The Boolean object is used to convert non-Boolean value to a Boolean"  
author: "Danish Khan"  
published: 2012-10-06  
updated: 2014-09-18  
canonical: https://www.mindstick.com/blog/372/boolean-object-in-javascript  
category: "javascript"  
tags: ["javascript"]  
reading_time: 2 minutes  

---

# Boolean Object in JavaScript

##### Introduction:\

[Boolean](https://www.mindstick.com/forum/160332/how-does-the-boolean-function-work) [objects](https://www.mindstick.com/forum/145447/what-are-objects) represent either of the two values, [true or false](https://www.mindstick.com/forum/160329/how-can-you-convert-a-value-to-a-boolean-true-or-false-in-javascript). The Boolean object is used to [convert](https://www.mindstick.com/forum/2093/configurationmanager-appsettings-convert-n-to-n-why) non-Boolean value to a Boolean value (i.e. true of false).

##### The Boolean Object Properties are:

1. Constructor: It returns the name of the [function](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server) that created the object [prototype](https://www.mindstick.com/news/2386/every-detail-regarding-twitter-leak-of-xiaomi-outfolding-smartphone-prototype).

2. Prototype: It allows us to [add or remove](https://www.mindstick.com/forum/160320/how-you-can-check-if-an-element-exists-in-a-set-and-add-or-remove-elements-from-it) [properties](https://www.mindstick.com/articles/23331/nootropics-7-different-types-and-their-unique-properties) and method

##### The Boolean Object Methods are :

##### 1. toString() : Returns a String representation of a Boolean Object.

##### \
2. valueOf(): Returns a primitive value of a Boolean Object.

##### \
3. toSource(): Returns a string containing the source of the object we can

##### use this string to create an equivalent object.

```
How to declare Boolean object:var myBooleanVal = new Boolean();
```

##### If the Boolean object has no value or the value like

· 0

· -0,

· False,

· NaN,

· undefined,

· null

· “”

then the object is set to false.

the below example clearly explains the above points:

```
<html xmlns="http://www.w3.org/1999/xhtml"><head>    <script type="text/javascript">        var boolean1 = new Boolean(1);        var boolean2 = new Boolean(0);        var boolean3 = new Boolean("");        var boolean4 = new Boolean("false");        var boolean5 = new Boolean(null);        var boolean6 = new Boolean(NaN);        document.write("1 is Boolean: " + boolean1 + "<br />");        document.write("0 is Boolean: " + boolean2 + "<br />");        document.write("Empty string is boolean: " + boolean3 + " <br />");        document.write("String False is Boolean: " + boolean4 + " <br />");        document.write("Null is Boolean: " + boolean5 + " <br />");        document.write("NaN is Boolean: " + boolean6 + " <br />");    </script></head><body></body></html> 
```

Output of the above [program](https://www.mindstick.com/blog/12337/scaling-up-your-mentorship-program) is:

![Boolean Object in JavaScript](https://www.mindstick.com/blogs/cd4acfeb-8bd6-4825-8a31-443ac226a668/images/cf9c30c7-acb8-4d56-bbea-514a5ccfe311.png)

##### Conclusions:

Through this blog we came to know about the Boolean object and how we can use it in our Java Script Program. Because these Boolean objects are very important part in programming language so we must know how to use it.

---

Original Source: https://www.mindstick.com/blog/372/boolean-object-in-javascript

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
