An alternative to Javascript's "
typeof
" that provides more consistent results...
Javascript's typeof operator
typeof {a: 4}; //"object" typeof [1, 2, 3]; //"object" (function() {return typeof arguments})(); //"object" typeof new ReferenceError; //"object" typeof new Date; //"object" typeof /a-z/; //"object" typeof Math; //"object" typeof JSON; //"object" typeof new Number(4); //"object" typeof new String("abc"); //"object" typeof new Boolean(true); //"object"
typeOf(stuff)
typeOf({a: 4}); //"object" typeOf([1, 2, 3]); //"array" (function() {return typeOf(arguments)})(); //"arguments" typeOf(new ReferenceError); //"error" typeOf(new Date); //"date" typeOf(/a-z/); //"regexp" typeOf(Math); //"math" typeOf(JSON); //"json" typeOf(new Number(4)); //"number" typeOf(new String("abc")); //"string" typeOf(new Boolean(true)); //"boolean"