CodesJava

Easy learning with example program codes

Javascript boolean object example


Javascript boolean object:

A JavaScript Boolean object can represents two values “true” or “false”.

How to create javascript boolean object:

1. By using boolean literals.
2. By using Boolean() constructor.

Syntax:

Var b1 = true;
var b2 = new Boolean(value);

Example:

<!DOCTYPE html>
<html>
<body>
<script>
var boolean1=new Boolean(true);
var boolean2=new Boolean(false); 
var boolean3=true;
document.write("Boolean1: "+boolean1+ "</br>");
document.write("Boolean2: "+boolean2+ "</br>");
document.write("Boolean3: "+boolean3);
</script>
</body>
</html>

Try it:

JS Bin on jsbin.com
 

JavaScript Boolean Object Properties

Property Description
constructor It returns a reference to the Boolean function that created the object.
prototype It allows us to add properties and methods to an object.

JavaScript Boolean Object Methods

Method Description
toSource() It returns a string containing the source of the Boolean object.
toString() It returns a string of object value.
valueOf() It returns the primitive value of the Boolean object.

 



Industrial Training

We offers Placement Oriented Training on Java, Spring, JSF, Hibernate, PHP, AngularJS, Angular 4, PLSQL, Oracle BI Publisher etc. We also provides Online training, please mail us at hr@codesjava.com.

Development

We also provides the Development services for Website Development , Java Development, PHP Development, Android App Development etc. You can contact us on hr@codesjava.com.

Copyright © 2019 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki