Created
May 8, 2014 05:22
-
-
Save holloway/ec6fad9288b8cc6787e7 to your computer and use it in GitHub Desktop.
get object type
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
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