JS:如何检查变量是否未定义

时间:2012-04-17 13:56:34

标签: javascript jquery undefined

我尝试过的东西似乎不起作用:

if(lastName != "undefined") 

if(lastName != undefined) 

if(undefined != lastName) 

1 个答案:

答案 0 :(得分:287)

var lastname = "Hi";

if(typeof lastname !== "undefined")
{
  alert("Hi. Variable is defined.");
}