Boolean
 
 
 

A Boolean is a TRUE or FALSE value usually represented with 1 bit (1=TRUE or 0=FALSE). However, the common representation in VBScript and JScript is VARIANT_TRUE (-1) and VARIANT_FALSE (0). These are often used as the return value of a function to indicate whether it failed or succeeded. VBScript, JScript, C#, and the C++ API all support the TRUE and FALSE keywords; PerlScript and Python do not.

Language

Comments

VBScript

VBScript uses the Boolean data type.

JScript

JScript uses the Boolean data type.

PerlScript

PerlScript does not have a specific type that represents Boolean values. Use integer values instead.

Python

Python does not have a specific type that represents Boolean values, but you can use either integer values or the built-in constants False (0) and True (1).

Note

These constants are context-sensitive, so false will not work.

C++

The C++ API uses bool.

C#

C# uses the bool type (System.Boolean).

Note

The bool type is set apart from the other basic data types (int, char, float, etc.) in that there is no conversion allowed between bool and the other types. This means that an empty string or 0 is not equivalent to false, and likewise a populated string or a non-zero value is also not equivalent to true.

Therefore, all condition tests (ie., tests to be evaluated in the context of if- or while-clauses) must strictly evaluate to a true bool value (other data types cannot be coerced/are not implicitly converted).

Tip

See Comparing Data Types across Languages for a table that compares the single-precision floating point data type across several different languages.

For high-level information about how these languages approach data type in general, see one of the following topics: