• Menu
  • Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

JavaBeat

Java Tutorial Blog

  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
    • Join Us (JBC)
  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
    • Join Us (JBC)

JavaScript Boolean Object

April 10, 2014 //  by Krishna Srinivasan//  Leave a Comment

The boolean object is used to represent the boolean value that is true or false. If the value is 0, -0, null, false, “”, undefined, NaN then it is considered as false value.

Syntax for Boolean Object

Following is the syntax to define Boolean variables using Javascript.

[code lang=”html”] var a= new boolean (value)
[/code]

Boolean Properties

Properties Description
constructor It is used to provide a reference to Boolean function of the particular object.
prototype It is used to add properties and methods.

Boolean Methods

Methods Description
toString( ) It specifies Boolean object(true or false) using string.
toSource( ) It is used to return the string using source code of the Boolean object.
valueOf( ) It is used to return the value of boolean object of the given parameter

Example Using Boolean Methods

[code lang=”html”] <html>
<body>
<script type="text/javascript">

var a = new Boolean(1);
document.write( "The value is : " + a.valueOf() );
document.write( "<br>The string is : " + a.toString() );

</script>
</body>
</html>
[/code]

  • In the above program we have used boolean methods.
  • We have used two methods in the program i.e. valueOf , toString.
  • We have declared a boolean variable “var = new Boolean( 1);” where 1 is equal to true.
  • document.write( “The value is : ” + a.valueOf() ); is used to return the value of the boolean object .
  • document.write( “The string is : ” + a.toString() ); is used to specify true or false using string.

Javascript Boolean Object Demo

  • Save the file as boolean_method.html in your system.
  • Just open the file in the browser, you will see the below picture in the browser.

When the execution process is completed successfully we will get the following output:

Javascript Boolean Object

Category: JavaScriptTag: JavaScript Tutorials

About Krishna Srinivasan

He is Founder and Chief Editor of JavaBeat. He has more than 8+ years of experience on developing Web applications. He writes about Spring, DOJO, JSF, Hibernate and many other emerging technologies in this blog.

Previous Post: « Eclipse Tips : Type Filters in Eclipse
Next Post: JSF Custom Error Pages »

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Follow Us

  • Facebook
  • Pinterest

FEATURED TUTORIALS

np.zeros

A Complete Guide To NumPy Functions in Python For Beginners

What is new in Java 6.0 Collections API?

The Java 6.0 Compiler API

Introductiion to Jakarta Struts

What’s new in Struts 2.0? – Struts 2.0 Framework

JavaBeat

Copyright © by JavaBeat · All rights reserved
Privacy Policy | Contact