For example I have a some code:
({}).toString.call(new Date()); // "[object Date]"
anybody knows, another methods how to check type?
(I wanna to receive only date
type without object)
For example I have a some code:
({}).toString.call(new Date()); // "[object Date]"
anybody knows, another methods how to check type?
(I wanna to receive only date
type without object)
The best way to check types the way you are asking to is using the method you already posted. You can make it a little bit easier though.
function type(value) {
const tag = Object.prototype.toString.call(value);
return tag.slice(8, -1);
}
console.log(type(new Date()));
console.log(type(5));
console.log(type(function() {}));