JavaScript Tutorial/Number Data Type/Boolean

Материал из Web эксперт
Перейти к: навигация, поиск

Boolean

The Boolean object is a wrapper object that holds a primitive Boolean value.

The Boolean object provides a method for converting the value to a string.

A primitive boolean can have only one of two states: true or false.

JavaScript uses the number 1 to represent true and 0 to represent false but provides the toString() method to return the strings "true" and "false".

A Boolean object is created with the Boolean() constructor and the new operator or by the Boolean() function.

Constructor:



var variable = new Boolean(value)
    var variable = Boolean(value)


Boolean Object Verses Primitive Boolean Value

<html>
    <script language="JavaScript">
    <!--
    boolObj = new Boolean("false");
    document.write("boolObj = ",boolObj);
    document.write(" [",typeof boolObj,"]<br>");
    boolVal = Boolean(false);
    document.write("boolVal = ",boolVal);       
    document.write(" [",typeof boolVal,"]");    
    -->
    </script>
</html>


Boolean.prototype

Syntax



Boolean.prototype.property
    Boolean.prototype.method


Boolean.toSource()

Syntax



boolean.toSource()


Boolean.toString()

Syntax



boolean.toString()


Boolean.valueOf()

Syntax



boolean.valueOf()