JavaScript Booleans

A Boolean object in JavaScript has two values true and false. Let us see how to create a Boolean and Boolean object. We will also see the Boolean properties and methods with live running examples.

Create a Boolean and Boolean object

Let us see how to create a Boolean:

We can create a Boolean object using the new keyword:

JavaScript Boolean Properties

We have a constructor property in the Boolean object. Let us understand the property with an example.

boolean.constructor

Using the constructor property, a reference to the Boolean function is returned. This function created the object. Let us see an example:

Output

JavaScript boolean constuctor

JavaScript Boolean Methods

We have built-in methods for the Boolean object. Let us understand some of the methods with examples:

  • toString()
  • valueOf()

JavaScript toString() method

Use the toString() method to return the string representation based on the value of the object. Let us see an example:

Output

JavaScript boolean toString() method

JavaScript valueOf() method

Use the valueOf() method in JavaScript to return the Boolean object. Let us see an example:

Output

JavaScript boolean valueOf() method

JavaScript Strings
JavaScript Math
Studyopedia Editorial Staff
Studyopedia Editorial Staff
[email protected]

We work to create programming tutorials for all.

No Comments

Post A Comment

Discover more from Studyopedia

Subscribe now to keep reading and get access to the full archive.

Continue reading