Created
March 25, 2018 03:36
-
-
Save gbhasha/1a6695c4f0c83521075a2f91add3dc9c to your computer and use it in GitHub Desktop.
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
function is(type, object) { | |
type = type[0].toUpperCase() + type.slice(1); | |
var toString = Object.prototype.toString; | |
return toString.call(object) === '[object ' + type + ']'; | |
} | |
console.log(is('object', {})); // true | |
console.log(is('array', [])); // true | |
console.log(is('object', [])); // false | |
console.log(is('number', 2)); // true | |
console.log(is('number', '2')); // false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment