Exforsys.com
 
Home Tutorials JavaScript
 

JavaScript Boolean Object

 

JavaScript Boolean Object Properties and Methods

Page 2 of 2


Property of Boolean Object:

Properties are the values associated with an object. A Boolean object has only one property, the value of the object - which is either true or false.



Methods used with Boolean Object:

Two methods used with Boolean Objects are:


valueOf()
toString()


valueOf():

valueOf() is used to return the primitive value of a Boolean object.


General Syntax of the valueOf method:


booleanObject.valueOf()



For example:



<
html>
   <body>
    
<script type="text/javascript">


          var exforsys = new Boolean(true)
          document.write(exforsys.valueOf())
    </script>
   </body>
</html>



In the above example, a boolean object exforsys is created with its initial value set as true. The value of the boolean object exforsys is printed using the valueOf() with the boolean object exforsys resulting in a true value.


toString():

The toString() method is used to convert a Boolean value to a string and returns the result.


General Syntax of the toString() method:


booleanObject.toString()



For example:



<
html>
   <body>
    
<script type="text/javascript">


          var exforsys = new Boolean(true)
          document.write(exforsys.toString())
    </script>
   </body>
</html>




The output of the above example is



true



In the above example, a boolean object exforsys is created with its initial value set as true. Then this Boolean value true is converted to a string using the method toString() along with the boolean object exforsys. This is outputs, resulting in a true string.




First Page: JavaScript Boolean Object


Read Next: JavaScript Array Object



 

 

Comments



Post Your Comment:

Members Please Login
Your Name:*
e-mail ID:(required for notification)*
Image Verification: 
 
 Subscribe    

Sponsored Links

 

Subscribe via RSS


Get Daily Updates via Subscribe to Exforsys Free Training via email


Get Latest Free Training Updates delivered directly to your Inbox...

Enter your email address:


 

Subscribe to Exforsys Free Training via RSS
 

 
Partners -  Privacy and Legal Policy -  Site News -  Contact   Sitemap  

Copyright © 2000 - 2009 exforsys.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape