JavaScript - boolean methods

revision:


list of boolean methods and description.

toSource() : returns a string containing the source of the Boolean object; you can use this string to create an equivalent object.

toString() : returns a string of either "true" or "false" depending upon the value of the object.

valueOf() : returns the primitive value of the Boolean object.


examples:

boolean.toSource()


boolean.toString()


boolean.valueOf()


code:
                <div>
                    <p>boolean.toSource() </p>
                    <a class="spec" id="boolean1"></a><br>
                    <p>boolean.toString()</p>
                    <a class="spec"  id="boolean2"></a><br>
                    <p>boolean.valueOf()</p>
                    <a class="spec" id="boolean3"></a><br>
                  
                </div>
                <script>
                    function book(title, publisher, price) {
                        this.title = title;
                        this.publisher = publisher;
                        this.price = price;
                    }         
                    var newBook = new book("Perl","Leo Inc",200); 
                   document.getElementById("boolean1").innerHTML = JSON.stringify(newBook);
        
                   var flag = new Boolean(false); 
                   document.getElementById("boolean2").innerHTML = "flag.toString is : " + flag.toString();
        
                   var flag1 = new Boolean(false); 
                   document.getElementById("boolean3").innerHTML = "flag.valueOf is : " + flag.valueOf();
        
                </script>