How can I check for an empty/null string in JavaScript?

Explanation

Here we will see that how can we check for an empty/null string in JavaScript. So if you just want to check if it is a truthy value, you can do:

if (strValue) {
    //do something
}

If you need to check specifically for an empty string over null. You have to use the following :

if (strValue === "") {
    //...
}

 

 

Also, read How do I list all files of a directory?

Share this post

Leave a Reply

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