👋 Hello! I'm Alphonsio the robot. Ask me a question, I'll try to answer.

How to check for an empty JS string ?

The best way to check if a JavaScript string is empty (whether there's any value) is to use the following:

if (myString) {
    // Do something
}


The following alternative will return true only if the type of myString is a string and the string is empty.

if (myString === '') {
    // Do something
}

You may also want to check if a string is empty or contains only spaces.

More