Created
March 11, 2013 12:13
-
-
Save georgeOsdDev/5133842 to your computer and use it in GitHub Desktop.
Yet another typeof function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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