if( typeof myVar === 'undefined' || myVar === null ){
// myVar is undefined or null
}
if(variable == null) //variable is undefined or null
//check for null or undefined with nullish coalescing operator
let value = null ?? "Oops.. null or undefined";
console.log(value) //Oops.. null or undefined
value = 25 ?? "Oops.. null or undefined";
console.log(value) // 25
value = "" ?? "Oops.. null or undefined";
console.log(value) // ""
var myVar=null;
if(myVar === null){
//I am null;
}
if (typeof myVar === 'undefined'){
//myVar is undefined
}
// simple check do the job
if (myVar) {
// comes here either myVar is not null,
// or myVar is not undefined,
// or myVar is not '' (empty string).
}
if( value ) {
}