debugging - Check if object exists in JavaScript -
how verify existence of object in javascript?
the following works:
if (!null) alert("got here");
but fails:
if (!maybeobject) alert("got here");
error: maybeobject not defined.
you can safely use typeof
operator on undefined variables.
if has been assigned value, including null, typeof return other undefined. typeof returns string.
therefore
if (typeof maybeobject != "undefined") { alert("got there"); }
Comments
Post a Comment