Skip to content

Instantly share code, notes, and snippets.

@holloway
Created May 8, 2014 05:22
Show Gist options
  • Save holloway/ec6fad9288b8cc6787e7 to your computer and use it in GitHub Desktop.
Save holloway/ec6fad9288b8cc6787e7 to your computer and use it in GitHub Desktop.
get object type
var get_type = function(thing){
if(thing===null) return "[object Null]";
else if(thing!==thing) return "[object NaN]";
return Object.prototype.toString.call(thing);
};
get_type([1]) // "[object Array]"
get_type({a:1}) // "[object Object]"
get_type(1) // "[object Number]"
get_type("test") // "[object String]"
get_type(undefined) // "[object Undefined]"
get_type(null) // "[object Null]"
get_type(true) // "[object Boolean]"
get_type(false) // "[object Boolean]"
get_type(NaN) // "[object NaN]"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment