ScanSkill

instanceof

The instanceof operator tests to see if the given object is an instance of a particular class.

Syntax

classObject instanceof ClassName

Example

class User {}
const user = new User();
console.log(user instanceof User); // Prints: true
console.log(user instanceof Object); //Prints: true

const name = new String("ScanSkill");
console.log(name instanceof String); //Prints: true

console.log(name instanceof Boolean); //Prints: false

The instanceof operator checks if the given object is an instance of a given class.