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!"
*/
// Test whether strValue is empty or is None
if (strValue) {
//do something
}
// Test wheter strValue is empty, but not None
if (strValue === "") {
//do something
}
if (!str.length) { ...
let myStr = null;
if (myStr === null || myStr.trim() === "") {
console.log("This is an empty string!");
} else {
console.log("This is not an empty string!");
}
if( value ) {
//
}
/**
* This will evaluate to true if value is not:
* null
* undefined
* NaN
* empty string ("")
* 0
* false
*/
/**
* Checks the string if undefined, null, not typeof string, empty or space(s)
* @param {any} str string to be evaluated
* @returns {boolean} the evaluated result
*/
function isStringNullOrWhiteSpace(str) {
return str === undefined || str === null
|| typeof str !== 'string'
|| str.match(/^ *$/) !== null;
}
// simple check do the job
if (myString) {
// comes here either myString is not null,
// or myString is not undefined,
// or myString is not '' (empty).
}
let str = "";
if (Boolean(str))
console.log("This is not an empty string!");
else
console.log("This is an empty string!");
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, ...
}
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
}