Saturday 25 January 2014

Boolean object

The Boolean object represents two values either "true" or "false".
Syntax:
Creating a boolean object:
var val = new Boolean(value);
If value parameter is omitted or is 0, -0, null, false, NaN, undefined, or the empty string (""), the object has an initial value of false.
Boolean Properties:
Here is a list of each property and their description.
Property
Description
Returns a reference to the Boolean function that created the object.
The prototype property allows you to add properties and methods to an object.
Boolean Methods
Here is a list of each method and its description.
Method
Description
Returns a string containing the source of the Boolean object; you can use this string to create an equivalent object.
Returns a string of either "true" or "false" depending upon the value of the object.
Returns the primitive value of the Boolean object.


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<script type="text/javascript">
 var b1=new Boolean();
 var b2=new Boolean(0);
 var b3=new Boolean(1);
 var b4=new Boolean(true);
 var b5=new Boolean(false);
 var b6=new Boolean("");
 var b7=new Boolean("abc");
 var b8=new Boolean("null");

 document.write("b1 :"+b1+"<br/>");
 document.write("b2 :"+b2+"<br/>");
 document.write("b3 :"+b3+"<br/>");
 document.write("b4 :"+b4+"<br/>");
 document.write("b5 :"+b5+"<br/>");
 document.write("b6 :"+b6+"<br/>");   
 document.write("b7 :"+b7+"<br/>"); 
 document.write("b8 :"+b8+"<br/>");  
</script> 
</body>
</html>
<! --b1 :false
b2 :false
b3 :true
b4 :true
b5 :false
b6 :false
b7 :true
b8 :true -->

No comments:

Post a Comment