Here is the code:
if (data.result.parameters.q === undefined ) {
colsole.log('undefined')
}
//I also tried
if (data.result.parameters.q === null) {
// colsole.log('undefined')
// }
Have tried using null and undefined but none works.
Here is the code:
if (data.result.parameters.q === undefined ) {
colsole.log('undefined')
}
//I also tried
if (data.result.parameters.q === null) {
// colsole.log('undefined')
// }
Have tried using null and undefined but none works.
a === undefined
doesn’t necessarily check for undefined
since you could set var undefined = {}
.
Use either the void
or typeof
operator (strict equality ===
isn’t necessary):
if(data.result.parameters.q == void(0) || typeof data.result.parameters.q == 'undefined')
console.log('data.result.parameters.q is undefined');
How does your data actually look? Are you sure that data
, data.result
and data.result.parameters
are set? There are plenty ways to check, like hasOwnProperty
or general truthiness:
if(data.hasOwnProperty('result') && data.result && data.result.hasOwnProperty('parameters'))
// now we can check if there is q in data.result.parameters
Also note there’s a spelling error in your code: it’s console
, not colsole
.