小编典典

如何检查 JavaScript 变量是否未定义?

all

我尝试过但似乎不起作用的事情:

if(lastName != "undefined")



if(lastName != undefined)



if(undefined != lastName)

阅读 64

收藏
2022-06-01

共1个答案

小编典典

var lastname = “Hi”;

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