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

Popular posts from this blog

SAP Web Service from .NET via WCF -

email - PHP Mail Error "The Page at X Says: E-Mail can not be sent!" -

Optimized Line drawing in QT -