Undefined test not working in javascript.
Posted
by
James South
on Stack Overflow
See other posts from Stack Overflow
or by James South
Published on 2010-12-24T11:48:09Z
Indexed on
2010/12/24
11:54 UTC
Read the original article
Hit count: 174
JavaScript
I'm getting the error 'foo' is undefined.
in my script when i test my function with an undefined parameter. As far as I understand, This shouldn't be happening.
My calling code:
//var foo
var test = peachUI().stringIsNullOrEmpty(foo) ;
My function (part of a larger framework).
stringIsNullOrEmpty: function (testString) {
/// <summary>
/// Checks to see if a given string is null or empty.
/// </summary>
/// <param name="testString" type="String">
/// The string check against.
/// </param>
/// <returns type="Boolean" />
var $empty = true;
if (typeof testString !== "undefined") {
if (testString && typeof testString === "string") {
if (testString.length > 0) {
$empty = false;
}
}
}
return $empty;
}
Any ideas?
Please note. I've had a good read of other similar questions before posting this one.
© Stack Overflow or respective owner