Created
January 21, 2013 13:04
-
-
Save alanshaw/4585888 to your computer and use it in GitHub Desktop.
JavaScript test for String
This file contains 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
function isString(str) { | |
return Object.prototype.toString.call(str) == '[object String]'; | |
} | |
/* | |
Test data: | |
isString(null) -> false | |
isString(undefined) -> false | |
isString([]) -> false | |
isString({}) -> false | |
isString(138) -> false | |
isString(1.138) -> false | |
isString(true) -> false | |
isString('a string') -> true | |
isString(new String('a string')) -> true | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment