How to Check type of an Object in JavaScript

const d = new Date();
if (d instanceof Date) {
    console.log("object is a Date type");
}

const num = 50;
if (num instanceof Number) {
    console.log("Number type");

}

const num2 = new Number(20);
if (num2 instanceof Number) {
    console.log("Type is : Number");
}

const num3 = 10;
if (typeof num3 == 'number') {
    console.log("Number type");

}

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *