Property Descriptors
Property Descriptors
Section titled “Property Descriptors”Introduction
Section titled “Introduction”Every property in JavaScript has a property descriptor — an object that describes its behavior. The three main attributes are writable, enumerable, and configurable.
Visual Explanation
Section titled “Visual Explanation”flowchart TD A["Property Descriptors"] B["writable: Can value be changed?"] C["enumerable: Shows up in loops?"] D["configurable: Can descriptor be changed?"]
A --> B A --> C A --> DGetting Descriptors
Section titled “Getting Descriptors”const user = { name: 'Alice' };
const descriptor = Object.getOwnPropertyDescriptor(user, 'name');// { value: 'Alice', writable: true, enumerable: true, configurable: true }Descriptor Attributes
Section titled “Descriptor Attributes”- writable —
trueif the value can be changed - enumerable —
trueif it appears infor...inandObject.keys() - configurable —
trueif the descriptor can be changed or property deleted
Summary
Section titled “Summary”- Every property has a descriptor with 3 boolean flags
writable— can the value change?enumerable— does it appear in iteration?configurable— can the descriptor be modified?