Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

How to Check for a Null or Empty String in JavaScript

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!"
*/
Source by www.freecodecamp.org #
 
PREVIOUS NEXT
Tagged: #How #Check #Null #Empty #String #JavaScript
ADD COMMENT
Topic
Name
9+7 =