How to create a Boolean object in JavaScript?

JavascriptWeb DevelopmentFront End Technology

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 −

Live Demo

<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>
raja
Published on 18-Jan-2018 12:00:39
Advertisements