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:



   <source lang="javascript">

var variable = new Boolean(value)

   var variable = Boolean(value)</source>
   
  

Boolean Object Verses Primitive Boolean Value

   <source lang="javascript">

<html>

   <script language="JavaScript">
   
   </script>

</html></source>


Boolean.prototype

Syntax



   <source lang="javascript">

Boolean.prototype.property

   Boolean.prototype.method</source>
   
  

Boolean.toSource()

Syntax



   <source lang="javascript">

boolean.toSource()</source>


Boolean.toString()

Syntax



   <source lang="javascript">

boolean.toString()</source>


Boolean.valueOf()

Syntax



   <source lang="javascript">

boolean.valueOf()</source>