javaScript boolean object

the javascript boolean object is an object wrapper for a boolean value.

boolean object is an object which holds bool values 'true' or 'false'.


              var    boolobj  =  new   boolean( value ) 


required.the variable name to which the boolean object is assigned.


optional.the initial boolean value for the new object.if value is omitted, or is false, 0, -0, null, nan, or an empty string(""), the initial value of the boolean object is false.otherwise, the initial value is true.


                     var     bool_1    =   new   boolean();                      // bool_1  is  false
                     var     bool_2    =   new   boolean(true);              //  bool_2  is  true 
                     var     bool_3    =   new   boolean(false);           //   bool_3  is  false
                     var     bool_4    =   new   boolean("");             //    bool_4  is  false
                     var     bool_5    =   new   boolean("34tr");     //   bool_5  is true

javaScript boolean object property

constructorspecifies the function that creates a boolean.
prototypeallows you to add properties and methods to a boolean object.

JavaScript boolean object methods

tostring()Converts a Boolean value to a string, and returns the result
valueof()Gets a reference to the Boolean.
      <head>  <title> javascript boolean object example </title> </head>
         var      bool    =  new   boolean(true);
         var      bool_1  =  new   boolean(false);
 document.write("the type of bool___"+ typeof(bool)+"___"+typeof(bool_1 ));
               var   s  =  bool.tostring();
               var  ss  =  bool_1.tostring();
 document.write('<br/>'+"the type of s  and ss____"+typeof (s)
                     +"_____"+typeof (ss) +"____s is____"+s+"_____ss  is___"+ ss );
         <body>  </html>