JavaScript

How to check if a string is empty in JavaScript

You can use the strict equality operator (===) to check if a string is empty or not.
 
The comparison str === "" returns true only if the data type of the value is string and it is not empty, otherwise returns false as shown in the following example:

if(str === ""){
    // The string 'str' is empty
}else{
    // The string 'str' is not empty
}
mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *