xxxxxxxxxx
var string = "not empty";
if(string == ""){
console.log("Please Add");
}
else{
console.log("You can pass"); // console will log this msg because our string is not empty
}
xxxxxxxxxx
let myStr = null;
if (myStr === null || myStr.trim() === "") {
console.log("This is an empty string!");
} else {
console.log("This is not an empty string!");
}
/*
This will return:
"This is an empty string!"
*/
xxxxxxxxxx
function IsEmptyOrWhiteSpace(str) {
return (str.match(/^\s*$/) || []).length > 0;
}
xxxxxxxxxx
// Test whether strValue is empty or is None
if (strValue) {
//do something
}
// Test wheter strValue is empty, but not None
if (strValue === "") {
//do something
}
xxxxxxxxxx
function isNullOrEmpty(str) {
return str === null || str.trim() === '';
}
// Usage example
const myString = null;
const result = isNullOrEmpty(myString);
console.log(result); // Output: true
xxxxxxxxxx
let myStr = null;
if (myStr === null || myStr.trim() === "") {
console.log("This is an empty string!");
} else {
console.log("This is not an empty string!");
}
xxxxxxxxxx
let str = "";
if (Boolean(str))
console.log("This is not an empty string!");
else
console.log("This is an empty string!");
xxxxxxxxxx
const str: string = ""; // the string to check
if (str.length === 0) {
console.log("String is empty");
} else {
console.log("String is not empty");
}
xxxxxxxxxx
// simple check do the job
if (myString) {
// comes here either myString is not null,
// or myString is not undefined,
// or myString is not '' (empty).
}