Search This Blog

Friday, 10 March 2017

Javascript::Check Type of JS Object

Check Type of JS Object

function objIs(type, obj) {
    var clas = Object.prototype.toString.call(obj).slice(8, -1);
    return obj !== undefined && obj !== null && clas === type;
}
 
objIs('String', 'test'); // true

objIs('String', new String('test')); // true

No comments:

Post a Comment