Possible Duplicate:
Detecting an undefined object property in JavaScript
javascript undefined compare
How we can add a check for an undefined variable, like:
function A(val) {
if (val == undefined)
// do this
else
// do this
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
JQuery library was developed specifically to simplify and to unify certain JavaScript functionality.
However if you need to check a variable against
undefinedvalue, there is no need to invent any special method, since JavaScript has atypeofoperator, which is simple, fast and cross-platform:It returns a string indicating the type of the variable or other unevaluated operand. The main advantage of this method, compared to
if (value === undefined) { ... }, is thattypeofwill never raise an exception in case if variablevaluedoes not exist.