如何在JavaScript中检查“未定义”? [重复] - How to check for “undefined” in JavaScript? [duplicate]

问题:

What is the most appropriate way to test if a variable is undefined in JavaScript? 测试JavaScript中是否未定义变量的最合适方法是什么? I've seen several possible ways: 我已经看到了几种可能的方法: java

if (window.myVariable)

Or 要么 app

if (typeof(myVariable) != "undefined")

Or 要么 测试

if (myVariable) //This throws an error if undefined. Should this be in Try/Catch?

解决方案:

参考一: https://stackoom.com/question/EDzo/如何在JavaScript中检查-未定义-重复
参考二: https://oldbug.net/q/EDzo/How-to-check-for-undefined-in-JavaScript-duplicate
相关文章
相关标签/搜索