Answers for "instanceof in javascript"

4

javascript detect if object is date

var myDate=new Date();
if(myDate instanceof Date){
    //im a hot Date
}
Posted by: Guest on August-01-2019
4

javascript detect if object is date

//checks if is object, null val returns false
function isObject(val) {
    if (val === null) { return false;}
    return ( (typeof val === 'function') || (typeof val === 'object') );
}
var person = {"name":"Boby Snark"};
isObject(person);//true
Posted by: Guest on July-24-2019
1

instanceof

function Phone(serial, price, color){
  this.serial = serial;
  this.price = price;
  this.color = color;
}

let phone1 = new Phone('abc1', 200, 'red');
let phone2 = new Phone('abc2', 400, 'green');

//instanceof 
console.log(phone1 instanceof Phone) // true

//constructor
console.log(phone1.constructor === Phone) //true
Posted by: Guest on July-24-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language