JavaScript Object getPrototypeOf() Method (original) (raw)
Last Updated : 26 May, 2023
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
function
myfun() { }
let obj =
new
myfun();
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
let first_var =
function
myFun() { };
let second_var = Object.create(first_var);
console.log(Object.getPrototypeOf
`` (second_var === first_var));
Output:
false
Supported Browser :
- Chrome
- Edge
- Firefox
- Opera
- Safari