Is there anything wrong with this test for undefined?
var undefined;
if(x == undefined){
//do something
}
or this:
function undefined(x){
return typeof x == 'undefined';
}
if(undefined(x)){
//do something
}
jsLint doesn’t throws a reserverd word error, but the code still seems to work…
Don’t redefine
undefined.Other programmers expect
undefinedto always beundefined, not a function for function’s sake.People often use
typeofoperator to ensure a reference error is not thrown when used to test for variables that areundefined.If anyone ever does this to you, you can use…
… to revert it back.