JavaScript Internals (521 Qs)•Part 5: ES6+ Modern Syntax, Classes, Modules & Destructuring (254 - 328)
What are the attributes provided by a property descriptor
A property descriptor is a record which has the following attributes
value: The value associated with the propertywritable: Determines whether the value associated with the property can be changed or notconfigurable: Returns true if the type of this property descriptor can be changed and if the property can be deleted from the corresponding object.enumerable: Determines whether the property appears during enumeration of the properties on the corresponding object or not.set: A function which serves as a setter for the propertyget: A function which serves as a getter for the property
Practical Code Example
javascript
// Property Descriptor Attributes:
const descriptor = Object.getOwnPropertyDescriptor({ x: 10 }, 'x');
console.log(descriptor);
// {
// value: 10,
// writable: true, // Can value be changed?
// enumerable: true, // Does it appear in for...in / Object.keys()?
// configurable: true // Can descriptor be modified or deleted?
// }