JavaScript Reflect.getPrototypeOf() method in JavaScript is used to return the prototype of the specified object.
Syntax:
Reflect.getPrototypeOf( obj )
Parameters: This method accepts a 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 prototype of the given object.
Exceptions: A TypeError is an exception given as the result when the target is invalid.
Below examples illustrate the Reflect.getPrototypeOf() method in JavaScript:
Example 1: In this example, we will get the prototype of the object using the Reflect.getPrototypeOf() method in JavaScript.
javascript
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
);
|
Output
[Object: null prototype] {}
null
true
Example 2: In this example, we will get the prototype of the object using the Reflect.getPrototypeOf() method in JavaScript.
javascript
console.log(Reflect.getPrototypeOf({}));
console.log(Reflect.getPrototypeOf(Object.prototype));
console.log(Reflect.getPrototypeOf(Object.create( null )));
|
Output
[Object: null prototype] {}
null
null
Supported Browsers:
The browsers are supported by JavaScript Reflect.getPrototypeOf() Method are listed below:
- Google Chrome 49 and above
- Edge 12 and above
- Firefox 42 and above
- Opera 36 and above
- Safari 10 and above
We have a complete list of Javascript Reflects methods, to check those go through the JavaScript Reflect Reference article.
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks 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!
Last Updated :
08 Aug, 2023
Like Article
Save Article