Skip to content

Instantly share code, notes, and snippets.

@sstur
Last active October 3, 2015 17:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sstur/2497849 to your computer and use it in GitHub Desktop.
Save sstur/2497849 to your computer and use it in GitHub Desktop.
A better typeof for JavaScript
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