Check if object exists in JavaScript

前端 未结 18 2691
抹茶落季
抹茶落季 2020-12-04 05:26

How do I verify the existence of an object in JavaScript?

The following works:

if (!null)
   alert(\"GOT HERE\");

But this throws a

18条回答
  •  悲哀的现实
    2020-12-04 05:41

    I used to just do a if(maybeObject) as the null check in my javascripts.

    if(maybeObject){
        alert("GOT HERE");
    }
    

    So only if maybeObject - is an object, the alert would be shown. I have an example in my site.

    https://sites.google.com/site/javaerrorsandsolutions/home/javascript-dynamic-checkboxes

提交回复
热议问题