How to Check empty/undefined/null String in JavaScript? Last Updated : 17 Nov, 2024 Comments Improve Suggest changes Like Article Like Report Empty strings contain no characters, while null strings have no value assigned. Checking for an empty, undefined, or null string in JavaScript involves verifying if the string is falsy or has a length of zero. Here are different approaches to check a string is empty or not.1. Using === OperatorUsing === operator we will check the string is empty or not. If empty then it will return "Empty String" and if the string is not empty it will return "Not Empty String".Syntaxif (str === "") { console.log("Empty String")} else { console.log("Not Empty String")} JavaScript // Function to check string is empty or not function checking(str){ // Checking the string using === operator if (str === "") { console.log("Empty String") } else { console.log("Not Empty String") } } // Checking for empty string checking(""); checking("GeeksforGeeks"); OutputEmpty String Not Empty String 2. Using length and ! OperatorThis approach uses length property to get the length of string and ! operator. and by using ! operator we will check string is empty or not. JavaScript // Function to check string is empty or not function checking(str) { return (!str || str.length === 0 ); } console.log(checking("")); console.log(checking("GeeksforGeeks")); Outputtrue false 3. Using replace() MethodThis approach uses replace() Method. It will ensure that the string is not just a group of empty spaces where we are doing replacement on the spaces. JavaScript // function to check string is empty or not function checking(str) { if(str.replace(/\s/g,"") == "") { console.log("Empty String") } else{ console.log("Not Empty String") } } checking(" "); checking("Hello Javascript"); OutputEmpty String Not Empty String Comment More infoAdvertise with us Next Article How to Check empty/undefined/null String in JavaScript? A AmanAgarwal6 Follow Improve Article Tags : JavaScript Web Technologies Similar Reads How to check for "undefined" value in JavaScript ? In JavaScript, undefined is a primitive value that represents the absence of a value or the uninitialized state of a variable. It's typically used to denote the absence of a meaningful value, such as when a variable has been declared but not assigned a value. It can also indicate the absence of a re 2 min read How to Check an Object is Empty using JavaScript? These are the following ways that can be used to Check an Object is Empty using JavaScript: 1. Using Object.keys() Method - Mostly usedThe Object.keys() method returns an array that contains the property names of an object. If the length of array is 0, then object is empty.JavaScriptlet obj = {}; if 2 min read How to check for null values in JavaScript ? The null values show the non-appearance of any object value. It is usually set on purpose to indicate that a variable has been declared but not yet assigned any value. This contrasts null from the similar primitive value undefined, which is an unintentional absence of any object value. That is becau 4 min read How to get the first non-null/undefined argument in JavaScript ? There are many occasions when we get to find out the first non-null or non-undefined argument passed to a function. This is known as coalescing. Approach 1: We can implement coalescing in pre-ES6 JavaScript by looping through the arguments and checking which of the arguments is equal to NULL. We the 5 min read JavaScript - How To Check if String Contains Only Digits? A string with only digits means it consists solely of numeric characters (0-9) and contains no other characters or symbols. Here are the different methods to check if the string contains only digits.1. Using Regular Expression (RegExp) with test() MethodThe most efficient way to check if a string co 3 min read Like