Created
August 18, 2014 01:41
-
-
Save Alex1990/d54917f1c3f5f3a8ce1e to your computer and use it in GitHub Desktop.
Check if a string is empty (not contains any characters)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Ref: http://stackoverflow.com/questions/154059/how-do-you-check-for-an-empty-string-in-javascript | |
*/ | |
// `str` must be a string | |
function isEmpty(str) { | |
return !!str.length; | |
} | |
// check if the `str` is empty, null or undefined (`str` may be 0 or false) | |
function isEmpty(str) { | |
return !str; | |
} | |
// check in `if` statement | |
// `str` may be a empty string, null, undefined, 0 or false | |
if (str) { | |
// statement... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment