相关疑难解决方法(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万
查看次数

如何检查变量或对象是否未定义?

我一直以为我可以通过比较未定义的var来检查未定义的var,但这是我在chrome控制台中得到的错误:

在此输入图像描述

我如何检查jQuery未定义的对象?

编辑:

在此输入图像描述

if(jQuery)也给我带来了问题

编辑:

方案:

if(window.jQuery)作品. typeof(jQuery) == 'undefined'也有效.

谁有人解释为什么?

javascript jquery

6
推荐指数
2
解决办法
1万
查看次数

标签 统计

javascript ×2

jquery ×1

undefined ×1