What are the methods of a boolean object in JavaScript?

JavascriptWeb DevelopmentFront End Technology

The following is a list of the methods of Boolean object −

Sr.No
Method & Description
1
toSource()

Returns a string containing the source of the Boolean object; you can use this string to create an equivalent object.
2
toString()

Returns a string of either "true" or "false" depending upon the value of the object.
3
valueOf()

Returns the primitive value of the Boolean object.

Example

Let’s see an example showing the usage of valueOf() method in JavaScript −

Live Demo

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

   <body>
      <script>
         var flag = new Boolean(false);
         document.write( "flag.valueOf is : " + flag.valueOf() );
      </script>
   </body>
</html>
raja
Published on 06-Feb-2018 15:00:34
Advertisements