![]() |
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 Content 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:
Applications:
Example: This example shows the use of instanceof operator.
Output true 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. Characteristics
Applications
Example: This example shows the use of isPrototypeOf() method.
Output true true true Difference Between instanceof and isPrototypeOf()
|
Reffered: https://www.geeksforgeeks.org
JavaScript |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 19 |