18. JavaScript Boolean Object

Javascript Boolean Object

Create a Boolean Object
Examples

The Boolean object is ued to convert a non-boolean value to a boolean value

Create a boolean object

The Boolean object repesents two values : true or false.
var myBoolean= new boolean();

If the boolean object has no initial value or if it is 0, -0,null, " ", false, undefined, or NaN, the object is set to false.
otherwise it is true

false:
var myBoolean=new Boolean();
var myBoolean=new Boolean(0);
var myBoolean=new Boolean(null);
var myBoolean=new Boolean(" ");
var myBoolean=new Boolean(false);
var myBoolean=new Boolean(NaN);

true:
var myBoolean=new Boolean(true);
var myBoolean=new Boolean("true");
var myBoolean=new Boolean("false");
var myBoolean=new Boolean("Richard");

Examples:
<html>
<body>
<script type="text/javascript">
var b1=new Boolean(0);
var b1=new Boolean(1);
var b1=new Boolean("");
var b1=new Boolean(null);
var b1=new Boolean(NaN);
var b1=new Boolean("false");
document.write("0 is boolean "+b1+"<br/>");
document.write("1 is boolean "+b2+"<br/>");
document.write("An empty string is boolian"+b3+"<br/>");
document.write("null is boolean"+b4+"<br/>");
document.write("NaN is boolean"+b5+"<br/>");
document.write("The string 'false' is boolean "+b6"<br/>");
</script>
</body>
</html>

No comments:

My Favorite Books

  • C and Data Structures by Ashok N. kamthane
  • Web Technologies by A. A. Puntambekar
  • Learn HTML and CSS with W3Schools
  • Learn JavaScript and Ajax with W3Schools
  • HTML5 Black Book: Covers Css3, Javascript,XML, XHTML, Ajax, PHP And Jquery
  • HTML5 Application Development Fundamentals: MTA Exam 98-375
  • .NET 4.0 Programming 6-In-1, Black Book
  • SQL Server 2008 R2 Black Book
  • Asp.net 4.0 Projects Covers: net 3.5 And .net 4.0 Codes, Black Book
  • UNIX Shell Programming 1 Edition by Yashavant Kanetkar
  • UNIX and Shell Programming 1 Edition by Richard F. Gilberg, Behrouz A. Forouzan
  • Computer Networks by Andrew S. Tanenbaum
  • Multiple Choice questions in computer science by Timothy J Williams