Skip to content

Instantly share code, notes, and snippets.

@RockyMyx
Last active December 17, 2015 06:38
Show Gist options
  • Save RockyMyx/5566430 to your computer and use it in GitHub Desktop.
Save RockyMyx/5566430 to your computer and use it in GitHub Desktop.
JavaScript: typeOf.js
function typeOf(obj) {
var _toString = Object.prototype.toString;
var _type ={
"undefined" : "undefined",
"number" : "number",
"boolean" : "boolean",
"string" : "string",
"[object Function]" : "function",
"[object RegExp]" : "regexp",
"[object Array]" : "array",
"[object Date]" : "date",
"[object Error]" : "error"
}
return _type[typeof obj] || _type[_toString.call(obj)] || (obj ? "object" : "null");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment