Things I’ve tried that don’t seem to work:
if(lastName != "undefined")
if(lastName != undefined)
if(undefined != lastName)
var lastname = "Hi";
if(typeof lastname !== "undefined")
{
alert("Hi. Variable is defined.");
}
lastname could take which would also match that condition - e.g. 0, null, '' (empty string). These are called "falsy" values.
if(lastName != undefined)This didn't work? Are you getting a ReferenceError in the console? If so, instead of avoiding the error by usingtypeof(as Crockford followers will suggest), you should be declaring your variables properly.