相关疑难解决方法(0)

如何在JavaScript中检查"undefined"?

在JavaScript中测试变量是否未定义的最合适方法是什么?我见过几种可能的方法:

if (window.myVariable)
Run Code Online (Sandbox Code Playgroud)

要么

if (typeof(myVariable) != "undefined")
Run Code Online (Sandbox Code Playgroud)

要么

if (myVariable) //This throws an error if undefined. Should this be in Try/Catch?
Run Code Online (Sandbox Code Playgroud)

javascript undefined

2294
推荐指数
14
解决办法
223万
查看次数

标签 统计

javascript ×1

undefined ×1