Estate atento porque en este tutorial vas a hallar el hallazgo que buscas.
Ejemplo 1: instancia de
Theinstanceof operator tests toseeif the prototype property of a constructor
appears anywhere in the prototype chain of an object. Thereturn value is a
booleanvalue.
For example :-
function Car(make, model, year)this.make = make;this.model = model;this.year = year;const auto =newCar('Honda','Accord',1998);
console.log(auto instanceofCar);// expected output: true
console.log(auto instanceofObject);// expected output: true
Ejemplo 2: Explicar sobre el operador instanceof en Java
Aninstanceof 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 withanull type through instanceof operator
returns a false.
Instanceof operator is used totest the object is of which type.
Syntax:<reference expression>instanceof<destination type>Instanceof returns trueif reference expression is subtype of destination type.
Instanceof returns falseif reference expression is null.
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)