JavaScript getPrototypeOf with Example

JavascriptWeb DevelopmentObject Oriented Programming

The getPrototypeOf() method is used to check prototype of user created object and is often used to compare if the two given objects have the same prototype or not.

Following is the code for getPrototypeOf() function −


 Live Demo

<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
   body {
      font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
   .sample {
      font-size: 18px;
      font-weight: 500;
<h1>JavaScript getPrototypeOf()</h1>
<div class="sample"></div>
<button class="Btn">CLICK HERE</button>
Click on the above button to get the prototype of object test
   let sampleEle = document.querySelector(".sample");
   function fun(name, age) { = name;
      this.age = age;
   document.querySelector(".Btn").addEventListener("click", () => {
      let test = new fun("Rohan", 22);
      sampleEle.innerHTML = "The prototype for test object is = " + Object.getPrototypeOf(test);


On clicking the “CLICK HERE” button −

Updated on 11-May-2020 12:18:39