Last active
July 18, 2016 10:55
-
-
Save khaled0fares/5dc2bc0cb214d2db0074b0a93d9e1d9b to your computer and use it in GitHub Desktop.
Type checking function in JS
This file contains 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
var isIt = function(that, type){ | |
return Object.prototype.toString.call(that) === ('[object '+ type + ']') | |
} | |
//Examples | |
isIt([1,2], "Array"); // true | |
isIt(undefined, "Undefined"); // true | |
isIt(true, "String") // false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment