SSh*_*rma 112 javascript
如果在页面中定义变量,我如何检入JavaScript?假设我想检查一个名为"x"的变量是否在页面中定义,如果我这样做if(x != null),它会给我一个错误.
SSh*_*rma 158
我让它使用 if (typeof(x) != "undefined")
And*_*ges 49
为了避免意外分配,我养成了颠倒条件表达式顺序的习惯:
if ('undefined' !== typeof x) {
Run Code Online (Sandbox Code Playgroud)
Pab*_*era 22
与其他运算符不同,typeof运算符在与未声明的符号一起使用时不会抛出ReferenceError异常,因此可以安全使用...
if (typeof a != "undefined") {
a();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
83778 次 |
| 最近记录: |