How to check for an empty JavaScript 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.
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.
The best way to check 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.
The best way to check 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
}
# | ID | Query | URL | Count |
---|