Difference Between instanceof and isPrototypeOf() in JavaScript Last Updated : 09 Jul, 2024 Comments Improve Suggest changes Like Article Like Report In JavaScript, understanding object relationships and type checks is crucial for the effective programming. The Two methods that facilitate these checks are instanceof and isPrototypeOf(). While both are used to the determine the type or prototype relationships in the JavaScript they operate differently and are suited for the different scenarios.These are the following topics that we are going to discuss:Table of ContentWhat is instanceof?What is isPrototypeOf()?Difference Between instanceof and isPrototypeOf()What is instanceof?The instanceof operator in JavaScript is used to the check if an object belongs to the particular class or constructor function. It returns true if the object is an instance of the specified class or constructor otherwise false.Characteristics:Type Check: Determines if an object is an instance of the specific class or constructor.Operator: instanceofUsage: object instanceof ClassReturns: Boolean Applications:Checking object types during the runtime.Ensuring compatibility with the expected object prototypes.Example: This example shows the use of instanceof operator. JavaScript class Vehicle { } class Car extends Vehicle { } let car = new Car(); console.log(car instanceof Car); console.log(car instanceof Vehicle); console.log(car instanceof Object); Outputtrue true true What is isPrototypeOf()?The isPrototypeOf() method checks if an object exists in the another object's prototype chain. It returns true if the specified object is in the prototype chain of the object on which it is called otherwise false.CharacteristicsPrototype Chain Check: Verifies if an object is present in the another object's prototype chain.Method: isPrototypeOf()Usage: prototypeObject.isPrototypeOf(object)Returns: Boolean ApplicationsThe Verifying inheritance relationships.Checking if an object inherits properties and methods from the another object.Example: This example shows the use of isPrototypeOf() method. JavaScript function Animal() { } function Dog() { } Dog.prototype = Object.create(Animal.prototype); let dog = new Dog(); console.log(Animal.prototype.isPrototypeOf(dog)); console.log(Object.prototype.isPrototypeOf(dog)); console.log(Dog.prototype.isPrototypeOf(dog)); Outputtrue true true Difference Between instanceof and isPrototypeOf()Characteristicsinstanceof isPrototypeOf()Type Check Checks if an object is an instance of the specific class or constructor function. Checks if an object exists in theanother object's prototype chain.SyntaxThe object instanceof Class The prototypeObject.isPrototypeOf(object)ReturnsBoolean Boolean UsageUsed with the classes or constructor functions. Used with the prototype objects.ApplicationsThe Runtime type checks determining object types. Verifying the inheritance relationships checking prototype chains. Comment More infoAdvertise with us Next Article Difference Between instanceof and isPrototypeOf() in JavaScript M mguru4c05q Follow Improve Article Tags : JavaScript Web Technologies Similar Reads Difference between interfaces and classes in TypeScript In this article, we will see what is the Difference between "interface" and "Classes" in TypeScript. Interface: Interface is the virtual structure that is used for type-checking. In TypeScript we use interface keyword to create the new interface with identity. It create the structure for the same da 3 min read Difference Between valueof and keyof in TypeScript In TypeScript, valueOf() retrieves the primitive value of an object, useful for accessing inherent data types. Conversely, keyof extracts keys as a union type, crucial for type-safe property referencing and dynamic type handling in TypeScript's type system.ValueOf() methodThe valueOf() method is a b 2 min read What are the differences between any vs Object in TypeScript? TypeScript is an open-source programming language. It is a superset of JavaScript language. TypeScript is designed for the development of large applications. any: It is a built-in data type in TypeScript which helps in describing the type of variable which we are unsure of while writing the code. Th 2 min read Difference between Array and Array of Objects in JavaScript ArrayAn Array is a collection of data and a data structure that is stored in a sequence of memory locations. One can access the elements of an array by calling the index number such as 0, 1, 2, 3, ..., etc. The array can store data types like Integer, Float, String, and Boolean all the primitive dat 3 min read JavaScript in and instanceof operators JavaScript Relational Operators are used to compare their operands and determine the relationship between them. They return a Boolean value (true or false) based on the comparison result.JavaScript in OperatorThe in-operator in JavaScript checks if a specified property exists in an object or if an e 3 min read Difference between double equal vs triple equal JavaScript Double equal: The double equal('==') operator tests for abstract equality i.e. it does the necessary type conversions before doing the equality comparison. Triple equal: The triple equal('===') operator tests for strict equality i.e it will not do the type conversion hence if the two values are not 2 min read TypeScript - Type Annotations and Type Inference TypeScript is a superset of JavaScript that adds static typing, helping developers catch errors early. Two core features are type annotations- where developers explicitly define variable, parameter, and return types, and type inference, where TypeScript automatically deduces types based on values or 5 min read TypeScript Instanceof Operator The TypeScript instanceof operator checks if an object is an instance of a specified class or constructor function at runtime. It returns a boolean value: `true` if the object is an instance of the type, and `false` otherwise, ensuring robust type checking during execution.SyntaxobjectName instanceo 3 min read How to define instance and non-instance properties ? In this article, we will try to understand how we could define as well as create an instance and non-instanced properties in JavaScript. Before analyzing instance and non-instanced properties let us first see the following syntax of creating a class in JavaScript since both instance and non-instance 3 min read How to Assert a Type of an HTMLElement in TypeScript ? In this article, we are going to learn the different ways of asserting the type of an HTMLElement in TypeScript. The type assertion is used to type the simple variables to JavaScript objects by defining the HTML element name. There are many ways of performing this task as listed below: Table of Cont 2 min read Like