js not instanceof
if ( !(obj instanceof Array) ) {
console.log('obj is not an Array')
}
js not instanceof
if ( !(obj instanceof Array) ) {
console.log('obj is not an Array')
}
Explain about instanceof operator in java
An instanceof in Java is a comparison operator which, given an object instance,
checks whether that instance is of a specified type (class/sub-class/interface)
or not. Just like other comparison operators, it returns true or false.
Comparing any object instance with a null type through instanceof operator
returns a false.
Instanceof operator is used to test the object is of which type.
Syntax : <reference expression> instanceof <destination type>
Instanceof returns true if reference expression is subtype of destination type.
Instanceof returns false if reference expression is null.
instanceof javascript
var color = "red";
var color2 = {};
color instanceof String // will return true
color2 instanceof Object // will return true
insanceof
The instanceof operator tests to see if the prototype property of a constructor
appears anywhere in the prototype chain of an object. The return value is a
boolean value.
For example :-
function Car(make, model, year) {
this.make = make;
this.model = model;
this.year = year;
}
const auto = new Car('Honda', 'Accord', 1998);
console.log(auto instanceof Car);
// expected output: true
console.log(auto instanceof Object);
// expected output: true
js class check if new instance
new Date() instanceof Date; // => true
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
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us