Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
a betterTypeOf
var betterTypeOf = function(obj) {
return ({})\s([a-zA-Z]+)/)[1].toLowerCase()
betterTypeOf(null); // null
betterTypeOf(NaN); // number
betterTypeOf({a: 4}); //"object"
betterTypeOf([1, 2, 3]); //"array"
(function() {console.log(toType(arguments))})(); //arguments
betterTypeOf(new ReferenceError); //"error"
betterTypeOf(new Date); //"date"
betterTypeOf(/a-z/); //"regexp"
betterTypeOf(Math); //"math"
betterTypeOf(JSON); //"json"
betterTypeOf(new Number(4)); //"number"
betterTypeOf(new String("abc")); //"string"
betterTypeOf(new Boolean(true)); //"boolean"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment