Computer >> Computer tutorials >  >> Programming >> Javascript

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);

Example

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

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

   <body>
      <script>
         var flag = new Boolean(true);
         document.write( "flag.toString is : " + flag.toString() );
      </script>
   </body>
</html>