Skip to content

Instantly share code, notes, and snippets.

@georgeOsdDev
Created March 11, 2013 12:13
Show Gist options
  • Select an option

  • Save georgeOsdDev/5133842 to your computer and use it in GitHub Desktop.

Select an option

Save georgeOsdDev/5133842 to your computer and use it in GitHub Desktop.
Yet another typeof function
console.log("------built in function 'typeof'-----");
console.log("typeof 'string' => ",typeof "string"); //string
console.log("typeof true => ",typeof true); //boolean
console.log("typeof 1 => ",typeof 1); //number
console.log("typeof null => ",typeof null); //object
console.log("typeof NaN => ",typeof NaN); //number
console.log("typeof Infinity => ",typeof Infinity); //Number
console.log("typeof undefined => ",typeof undefined); //undefined
console.log("typeof new Object() => ",typeof new Object()); //object
console.log("typeof new Array => ",typeof new Array()); //object
console.log("typeof new Function() => ",typeof new Function()); //function
console.log("------yet another function 'typeOf'-----");
var typeOf = function(that){
var t = Object.prototype.toString.call(that);
return t.split(" ")[1].replace("]","");
};
console.log("typeOf('string')) => ", typeOf("string")); //String
console.log("typeOf(true)) => ", typeOf(true)); //Boolean
console.log("typeOf(1)) => ", typeOf(1)); //Number
console.log("typeOf(null)) => ", typeOf(null)); //Null
console.log("typeOf(NaN)) => ", typeOf(NaN)); //Number
console.log("typeOf(Infinity)) => ", typeOf(Infinity)); //Number
console.log("typeOf(undefined)) => ", typeOf(undefined)); //Undefined
console.log("typeOf(new Object())) => ", typeOf(new Object())); //Object
console.log("typeOf(new Array())) => ", typeOf(new Array())); //Array
console.log("typeOf(new Function()) => ", typeOf(new Function())); //Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment