HTML JavaScript

Boolean object in JavaScript

The Boolean object represents two values either “true” or “false”.

new Boolean(value);

If value parameter is omitted, 0, -0, null, false, NaN, undefined, or the empty string (“”), the object has an initial value of false due to automatic type coercion.

Here’s a simple test for the JavaScript boolean object, here’s the HTML anchor tag I used to call a function:

<a href=”” onclick=”GetBoolean(‘true’); return false;”>Get Boolean</a>

Here’s the JavaScript function:

function GetBoolean(bBool){
	//Create a boolean object
	var myBoolean = new Boolean();
	myBoolean = true;
	if(myBoolean) alert('myBoolean = ' + myBoolean);
	if(myBoolean) alert('bBool = ' + bBool);
	if(bBool == myBoolean){
		alert('bBool == myBoolean');
	} else {
		alert('bBool <> myBoolean');