How to Check for a Null or Empty String in JavaScript
Dec 26, 2024
Use: https://www.freecodecamp.org/news/javascript-check-empty-string-checking-null-or-empty-in-js/
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!"