Boolean values: Difference between revisions
Content added Content deleted
(added VB & PB; changed smart quotes to normal quotes under TCL) |
(add JavaScript) |
||
Line 131: | Line 131: | ||
=={{header|Java}}== |
=={{header|Java}}== |
||
Java has <tt>true</tt> and <tt>false</tt> keywords, representing the only values of type <tt>boolean</tt>. There are also object wrappers <tt>Boolean.TRUE</tt> and <tt>Boolean.FALSE</tt>, of type <tt>Boolean</tt> which may be un-boxed into <tt>boolean</tt>s (auto-unboxed in Java 1.5+). There are no automatic conversions from any other types into <tt>boolean</tt>, and it is a compile-time error to use any type other than <tt>boolean</tt> or <tt>Boolean</tt> in a place that expects a <tt>boolean</tt> (e.g. if-statement condition, while-statement condition, operand of a logical operator, etc.). |
Java has <tt>true</tt> and <tt>false</tt> keywords, representing the only values of type <tt>boolean</tt>. There are also object wrappers <tt>Boolean.TRUE</tt> and <tt>Boolean.FALSE</tt>, of type <tt>Boolean</tt> which may be un-boxed into <tt>boolean</tt>s (auto-unboxed in Java 1.5+). There are no automatic conversions from any other types into <tt>boolean</tt>, and it is a compile-time error to use any type other than <tt>boolean</tt> or <tt>Boolean</tt> in a place that expects a <tt>boolean</tt> (e.g. if-statement condition, while-statement condition, operand of a logical operator, etc.). |
||
=={{header|JavaScript}}== |
|||
The Boolean type has two values: <code>true</code> and <code>false</code> |
|||
The following table shows the result of type conversions to boolean: |
|||
* Undefined: any undefined value is converted to <code>false</code> |
|||
* Null: <code>false</code> |
|||
* Number: the numbers <code>0</code>, <code>-0</code>, <code>NaN</code> are <code>false</code>; otherwise <code>true</code> |
|||
* String: the empty (zero-length) string is <code>false</code>; otherwise <code>true</code> |
|||
* Object: any object is converted to <code>true</code> |
|||
(source: [http://www.ecma-international.org/publications/standards/Ecma-262.htm ECMAScript Language Reference]) |
|||
=={{header|Logo}}== |
=={{header|Logo}}== |