![]() |
VOOZH | about |
JavaScript Reflect.getOwnPropertyDescriptor() method in Javascript is used to get the descriptor of an object if it exists in the object. It is the same as the Object.getOwnPropertyDescriptor method, but non-object targets are handled differently.
Syntax:
Reflect.getOwnPropertyDescriptor(obj, Key)
Parameters: This method accepts two parameters as mentioned above and described below:
Return value: This method returns the property descriptor object and returns undefined if the target object does not exist.
Exceptions: A TypeError is an exception given as the result when the target is not an Object.
Below examples illustrate the Reflect.getOwnPropertyDescriptor() method in JavaScript:
Example 1: In this example, we will get the descriptor of an object using Reflect.getOwnPropertyDescriptor() method in JavaScript.
geeks undefined true Javascript undefined true true
Example 2: In this example, we will get the descriptor of an object using the Reflect.getOwnPropertyDescriptor() method in JavaScript.
undefined
true
{ value: 'NULL', writable: true, enumerable: true, configurable: true }
{
value: 'hello',
writable: true,
enumerable: true,
configurable: true
}
undefined
{ value: 0, writable: ...
Example 3: Calling the non-object and an error occurs.
Output:
Error: Reflect.getOwnPropertyDescriptor called on non-object
The browsers are supported by JavaScript Reflect.getOwnPropertyDescriptor() Method are listed below:
We have a complete list of Javascript Reflects methods, to check those go through the JavaScript Reflect Reference article.