Skip to content

Instantly share code, notes, and snippets.

@alanshaw
Created January 21, 2013 13:04
Show Gist options
  • Save alanshaw/4585888 to your computer and use it in GitHub Desktop.
Save alanshaw/4585888 to your computer and use it in GitHub Desktop.
JavaScript test for String
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