Skip to content

Instantly share code, notes, and snippets.

@khaled0fares
Last active July 18, 2016 10:55
Show Gist options
  • Save khaled0fares/5dc2bc0cb214d2db0074b0a93d9e1d9b to your computer and use it in GitHub Desktop.
Save khaled0fares/5dc2bc0cb214d2db0074b0a93d9e1d9b to your computer and use it in GitHub Desktop.
Type checking function in JS
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