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 -

Optimized Line drawing in QT -

datetime - str to time in python -