JS Strict Data Types - Boolean

Tagged:  

Back to Main Documentation Page
The JS Strict Data Types Boolean method allows you to define a variable as a Boolean data type and maintain the value as a Boolean. The Boolean method returns true or false, but will accept true, false, 1 or 0.

To identify a variable as a Boolean you would write the below code (where OptionalBooleanValue is some Boolean value, if no value is inserted then an empty Boolean is returned).

MyVar1 = new Boolean(OptionalBooleanValue);

To return the data type of the Boolean you would use the DataType property.

alert(MyVar1.DataType);

To set the value of the Boolean to a new value you would use the below code (where BooleanValue is some Boolean value).

MyVar1.Set(BooleanValue);

To get the value of a Boolean you would use the value property (the below would display the value).

alert(MyVar1.value);

To compare if a Boolean is equal to the Boolean value you would use the CompareEq method as seen below (below is how you would use the CompareEq method in an if statement, where BooleanValue is some Boolean value).

if(MyVar1.CompareEq(BooleanValue)){
    alert("Statement is Equal");
{

To compare if a Boolean is not equal to the Boolean value you would use the CompareNotEq method as seen below (below is how you would use the CompareNotEq method in an if statement, where BooleanValue is some Boolean value).

if(MyVar1.CompareNotEq(BooleanValue)){
    alert("Statement is not Equal");
{

Below is an example of how you would use a function to maintain a Boolean value.

function TestFunction(MyVar1){
    //Set the Data Type of each Variable
    MyVar1 = new Boolean(MyVar1);
    alert("MyVar1 = " + MyVar.value);
}