If Not (oResponse.selectSingleNode("BigGroupType") Is Nothing) Then
End If
I need to convert this to javascript. Is that enough to check null
?
This was my lead's answer, plz verify this,
if(typeof $(data).find("BigGroupType").text() != "undefined" && $(data).find("BigGroupType").text() != null) {
}
JavaScript has two values which mean "nothing", undefined
and null
. undefined
has a much stronger "nothing" meaning than null
because it is the default value of every variable. No variable can be null
unless it is set to null
, but variables are undefined
by default.
var x;
console.log(x === undefined); // => true
var X = { foo: 'bar' };
console.log(X.baz); // => undefined
If you want to check to see if something is undefined
, you should use ===
because ==
isn't good enough to distinguish it from null
.
var x = null;
console.log(x == undefined); // => true
console.log(x === undefined); // => false
However, this can be useful because sometimes you want to know if something is undefined
or null
, so you can just do if (value == null)
to test if it is either.
Finally, if you want to test whether a variable even exists in scope, you can use typeof
. This can be helpful when testing for built-ins which may not exist in older browsers, such as JSON
.
if (typeof JSON == 'undefined') {
// Either no variable named JSON exists, or it exists and
// its value is undefined.
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With