Boolean object in JavaScript

2 Comments

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.

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

<a href=”http://www.melvinswebstuff.com” 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');
	}

}

Check if Javascript function exists

Comments Off

Here’s a way to check to see if a function exist before calling it.

if (typeof(functionName) != "undefined") {
   functionName(); // safe to use the function
}

Inline IF’ Statement

Comments Off

C#

string s;
s = (true ? "True" : "False"); //s will be "True"

VB.NET

Dim s As String
s = If(True, "True", "False") 's will be "True"
'In the following you cannot rely on a particular function
'not being called if the other argument is selected by Expression
'(notice IIf vs. If)
s = IIf(True, "True", "False") 's will be "True"

JavaScript

var s = (true) ? 'True' : 'False'; //s will be "True"