Working with Boolean object using JavaScript

A Boolean object is a wrapper class and a member of global objects. It is used to convert non Boolean values into Boolean values. It has two values: true and false. The Boolean object returns false when the object is passed with values, such as, 0, “ ” (empty string), false, null, undefined and Not a Number (NAN) values. The Boolean object can be created in the following ways:

  • Using Boolean literal notation.
  • Using Boolean object as function.
  • Using the testable expressions.

Demo

  1. Let us create a document named BooleanTest.html.

    notepad

  2. Write the following code:

    html

  3. Execute the script by Opening the file in the Web Browser. If you are using Internet Explore click on “Allow Blocked Content” to allow the script to execute and you are using Mozilla Firefox then click on allow “ActiveX Controls”.

    output