Skip to content
Related Articles

Related Articles

Improve Article
JavaScript | getPrototypeOf() with Examples
  • Last Updated : 25 Sep, 2018

The getPrototypeOf() is an inbuilt function in JavaScript which is used to check the prototype of an object that the user has created. Most of the times, It is used to check whether two objects have the same prototype or not. 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 code to show the working of getPrototypeOf() function:

Code #1:






<script>
  
  // Creating a simple function
  function myfun(){}
    
  // creating a new object
  var obj= new myfun();
    
  // getting the prototype
  document.write(Object.getPrototypeOf(obj)); 
  
</script>

Output:

[object Object]

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




<script>
   
  // Creating a simple function
  var first_var = function myFun() {};
    
  // Creating a object
  var second_var = Object.create(first_var);
  
  // Getting the output
  document.write(Object.getPrototypeOf(second_var === first_var));
  
</script>

Output:

false
My Personal Notes arrow_drop_up
Recommended Articles
Page :