If Not (oResponse.selectSingleNode("BigGroupType") Is Nothing) Then
End If
我需要将其转换为 javascript。这足以检查 null
吗?
这是我领导的回答,请核实一下,
if(typeof $(data).find("BigGroupType").text() != "undefined" && $(data).find("BigGroupType").text() != null) {
}
最佳答案
JavaScript 有两个表示“无”的值,undefined
和 null
。 undefined
比 null
具有更强的“无”含义,因为它是每个变量的默认值。除非将变量设置为null
,否则任何变量都不能为null
,但变量默认为未定义
。
var x;
console.log(x === undefined); // => true
var X = { foo: 'bar' };
console.log(X.baz); // => undefined
如果你想检查是否有undefined
,你应该使用===
因为==
不够好以区别于 null
。
var x = null;
console.log(x == undefined); // => true
console.log(x === undefined); // => false
但是,这可能很有用,因为有时您想知道某些内容是否为 undefined
或 null
,因此您只需执行 if (value == null)
来测试它是否是。
最后,如果你想测试一个变量是否存在于范围内,你可以使用typeof
。这在测试旧版浏览器中可能不存在的内置函数时很有用,例如 JSON
。
if (typeof JSON == 'undefined') {
// Either no variable named JSON exists, or it exists and
// its value is undefined.
}
关于javascript - vbscript `Is Nothing` 的 javascript 等价物是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13763495/