An empty string is falsy in JavaScript
Instead of using aString.length > 0
to verify if a string has a valid value, you can use the string as the conditional itself.
This is due to an empty string ''
being considered falsy in JavaScript:
javascript
1function isNotEmpty(aString) {
2 return Boolean(aString)
3}
4
5isNotEmpty('Hello, World!') // outputs: true
6isNotEmpty('') // outputs: false
The other falsy JavaScript values are:
false
null
undefined
0
NaN