How to use instanceof operator in Node.js

2 Answers

0 votes
const o = {x: 14, y: 35};
console.log(o instanceof Date); 
console.log(o instanceof Object); 
console.log(o instanceof String); 
console.log("--")
 
const d = new Date(); 
console.log(d instanceof Date); 
console.log(d instanceof Object); 
console.log(d instanceof String); 
console.log("----")
 
const s = "string primitive";
console.log(s instanceof Date); 
console.log(s instanceof Object); 
console.log(s instanceof String); 
console.log("------")
 
const so = new String("String object");
console.log(so instanceof Date); 
console.log(so instanceof Object); 
console.log(so instanceof String); 
 
 
 
 
 
/*
run:
 
false
true
false
--
true
true
false
----
false
false
false
------
false
true
true
 
*/

 



answered Jan 27, 2022 by avibootz
edited Jan 27, 2022 by avibootz
0 votes
function func(a, b) {
    this.a = a;
    this.b = b;
}
const result = new func(3, 8);
 
console.log(result instanceof func);
console.log(result instanceof Object);

console.log(func instanceof func);
console.log(func instanceof Object);
 
 
 
 
/*
run:
 
true
true
false
true
 
*/

 



answered Jan 27, 2022 by avibootz

Related questions

1 answer 201 views
2 answers 361 views
1 answer 255 views
2 answers 353 views
4 answers 808 views
...