Last active
October 3, 2015 17:48
-
-
Save sstur/2497849 to your computer and use it in GitHub Desktop.
A better typeof for JavaScript
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 typeOf(o) { | |
var type = (o === null) ? 'null' : typeof o; | |
return (type == 'object') ? Object.prototype.toString.call(o).slice(8, -1).toLowerCase() : type; | |
} | |
//Example: typeOf(new Date()) => 'date' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment