JavaScript | Reflect.getPrototypeOf() Method

The Reflect.getPrototypeOf() method in JavaScript is used to return the prototype of the specified object.

Syntax:

Reflect.getPrototypeOf( obj ) 

Parameters: This method accepts single parameter as mentioned above and described below:

  • obj: This parameter is the target object and it is used to get the prototype.

Return value: This method is used to get the returned the prototype of the given object.

Exceptions: A TypeError is exception given as the result, when the target is invalid.



Below examples illustrate the Reflect.getPrototypeOf() method in JavaScript:

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<script>
const object1 = {
    property1: 356
};
  
const result = Reflect.getPrototypeOf(object1);
console.log(result);
console.log(Reflect.getPrototypeOf(result));
  
const result1 = Object.create (null);  
console.log (  
 Reflect.getPrototypeOf ( result1 ) === null  
);   
</script>

chevron_right


Output:

Object {  }
null
true

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<script>
console.log (Reflect.getPrototypeOf({}));       
console.log (Reflect.getPrototypeOf(Object.prototype));  
console.log (Reflect.getPrototypeOf(Object.create(null)));
</script>

chevron_right


Output:

Object {  }
null
null

Supported Browsers: The browsers supported by JavaScript Reflect.getPrototypeOf() Method are listed below:

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Opera
  • Safari
  • Edge

full-stack-img

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.