FrontendDeveloper.in

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,

  1. value: The value associated with the property (data descriptors only).
  2. writable: true if and only if the value associated with the property may be changed
  3. get: A function which serves as a getter for the property.
  4. set: A function which serves as a setter for the property.
  5. configurable: true if and only if the type of this property descriptor may be changed or deleted.
  6. 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 }}
Back to all ECMAScript questions
Get LinkedIn Premium at Rs 399