在Javascript中检查变量是否在范围内

Vai*_*ain 4 javascript

我需要检查当前作用域中是否存在对象"objCR".我尝试使用下面的代码.

if(objCR == null)
alert("object is not defined");
Run Code Online (Sandbox Code Playgroud)

让我知道我错在哪里.

Ode*_*ded 8

使用typeof运营商:

if(typeof objCR == "undefined")
   alert("objCR is not defined");
Run Code Online (Sandbox Code Playgroud)