Skip to content

Instantly share code, notes, and snippets.

@gbhasha
Created March 25, 2018 03:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gbhasha/1a6695c4f0c83521075a2f91add3dc9c to your computer and use it in GitHub Desktop.
Save gbhasha/1a6695c4f0c83521075a2f91add3dc9c to your computer and use it in GitHub Desktop.
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