Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function getClass(obj) {
- if (typeof obj === "undefined")
- return "undefined";
- if (obj === null)
- return "null";
- return Object.prototype.toString.call(obj)
- .match(/^\[object\s(.*)\]$/)[1];
- }
- getClass("") === "String";
- getClass(true) === "Boolean";
- getClass(0) === "Number";
- getClass([]) === "Array";
- getClass({}) === "Object";
- getClass(null) === "null";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement