How to create a Boolean object in JavaScript?

The Boolean object represents two values, either "true" or "false". If the value parameter is omitted or is 0, -0, null, false, NaN, undefined, or the empty string (""), the object has an initial value of false.

Create a Boolean object like this −

var val = new Boolean(value);


You can try to run the following code to learn how to create a Boolean object −

Live Demo

      <title>JavaScript toString() Method</title>

         var flag = new Boolean(true);
         document.write( "flag.toString is : " + flag.toString() );