Saturday, November 16, 2024
Google search engine
HomeLanguagesJavascriptJavaScript Object getPrototypeOf() Method

JavaScript Object getPrototypeOf() Method

The Javascript getPrototypeOf() is an inbuilt function in JavaScript that is used to check the prototype of an object that the user has created. Most of the time, It is used to check whether two objects have the same prototype or not. The prototype here means the internal definition of the object that is defined by the user in the JavaScript code. 
Syntax:  

Object.getPrototypeOf(created_object);

Parameters: It accepts a parameter “created object” which is the object of the entity whose prototype going to be found out. 

Return Value: It returns the internal prototype of the object passed in the method.

JavaScript examples to show the working of the getPrototypeOf() function: 

Example 1: This example shows the basic use of the getPrototypeOf() function in javascript.

javascript




// Creating a simple function
function myfun() { }
  
// creating a new object
let obj = new myfun();
  
// getting the prototype
console.log(Object.getPrototypeOf(obj));


Output: 

[object Object]

Example 2: Another application of the getPrototypeOf() function is to check whether two objects have the same prototype or not. 

javascript




// Creating a simple function
let first_var = function myFun() { };
  
// Creating a object
let second_var = Object.create(first_var);
  
// Getting the output
console.log(Object.getPrototypeOf
    (second_var === first_var));


Output: 

false

Supported Browser :

  • Chrome
  • Edge 
  • Firefox
  • Opera
  • Safari
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

RELATED ARTICLES

Most Popular

Recent Comments