ECMAScript question detail
Object property descriptors
Property descriptors describe the attributes of a property. The Object.getOwnPropertyDescriptors() method returns all own property descriptors of a given object.
It provides the below attributes,
- value: The value associated with the property (data descriptors only).
- writable: true if and only if the value associated with the property may be changed
- get: A function which serves as a getter for the property.
- set: A function which serves as a setter for the property.
- configurable: true if and only if the type of this property descriptor may be changed or deleted.
- enumerable: true if and only if this property shows up during enumeration of the property.
The usage of finding property descriptors for any property seems to be as below,
const profile = {
age: 42
};
const descriptors = Object.getOwnPropertyDescriptors(profile);
console.log(descriptors); // {age: {configurable: true, enumerable: true, writable: true }}