User Tools

Site Tools


Boolean

ECMAScript Boolean prototype object.

More...

Inherits :

Methods

ECMAScript
StringtoString ()
NumbervalueOf ()

Detailed Description

ECMAScript provides a Boolean data type that can have one of two primitive values, true or false. In general, creating objects of this type is not recommended since the behavior will probably not be what you would expect. Instead, assign the literal value true or false as required.

Any expression can be evaluated in a boolean context (e.g. in logical operations, such as conditionals). If the expression's value is 0, null, false, NaN, undefined or an empty String, the expression is false; otherwise the expression is true.

Example:

Creating boolean values using the true/false constants

var bOn = true;
var bOff = false;

Example:

Creating a boolean values using the evaluation of expressions

var nVal1 = 5;
var nVal2 = 6;
var bEqual = (nVal1 == nVal2);
var bLessThan = (nVal1 < nVal2);
var bGreaterThan = (nVal1 > nVal2);

Methods


String : toString()

Return Value:

  • The value of the Boolean object as a String; i.e. “true” or “false”.

Number : valueOf()

Return Value:

  • The primitive value of the Boolean object; i.e. true or false.