Working with Boolean object using JavaScript

Introduction

 
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 the Boolean literal notation.
  • Using the Boolean object as a 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 Explorer click on “Allow Blocked Content” to allow the script to execute and you are using Mozilla Firefox then click on allow “ActiveX Controls”.
     
    output