javascript check if undefined or null or empty string
// simple check do the job
if (myString) {
// comes here either myString is not null,
// or myString is not undefined,
// or myString is not '' (empty).
}
//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) // ""
Use for Empty string, undefined, null, ...
//To check for a truthy value:
if (strValue) {
// strValue was non-empty string, true, 42, Infinity, [], ...
}
//To check for a falsy value:
if (!strValue) {
// strValue was empty string, false, 0, null, undefined, ...
}