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

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -