Test JavaScript function parameters with isEmpty()

Often when you create a custom function that accepts arguments, you'll want to determine if these parameters actually contain values before executing other portions of script. While JavaScript doesn't provide a built-in function of its own to do so, we've created a handy function of our own:

function isEmpty(inputVal) {if (inputVal == null || inputVal==\"\")
{ return true} else { return false }}

You might use this function like so:

function doAddition(val1, val2)
{var _val1 = (isEmpty(val1))?0:val1var _val2 = (isEmpty(val2))?.5:val2return _val1 + _val2}

ith this procedure in place, the following JavaScript statement:
alert(doAddition()) would generate an alertbox with 0.5 in it.

Source: Mike D. Jones
Viewed 3179 times