Suggest an editImprove this articleRefine the answer for “The writable, enumerable, configurable flags?”. Your changes go to moderation before they’re published.Approval requiredContentWhat you’re changing🇺🇸EN🇺🇦UAPreviewTitle (EN)Short answer (EN)**The `writable`, `enumerable` and `configurable` flags** are three service parameters in a property descriptor that control the behavior of object properties in JavaScript. **Key point:** `writable` allows changing the property's value, `enumerable` makes it visible during enumeration (`for...in`, `Object.keys`), and `configurable` allows deleting the property and changing its flags.Shown above the full answer for quick recall.Answer (EN)ImageThe `writable`, `enumerable` and `configurable` flags are three service parameters (flags) in a **property descriptor** that control the **behavior of object properties** in JavaScript. These flags are not visible during regular use, but they **determine whether a property can be changed, deleted or enumerated**. ## Summary | Flag | What it does | Default | |---|---|---| | `writable` | Allows changing the property's value | `false` (if the property was created via `defineProperty`) | | `enumerable` | Makes the property visible during enumeration (`for...in`, `Object.keys`) | `false` | | `configurable` | Allows deleting the property and changing its flags | `false` | ## Example for all three ```javascript const user = {}; Object.defineProperty(user, 'name', { value: 'Tim', writable: false, // cannot be changed enumerable: false, // does not appear in loops configurable: false // cannot be deleted or have its flags changed }); console.log(user.name); // "Tim" user.name = 'Oleh'; // will not change delete user.name; // will not be deleted console.log(Object.keys(user)); // [] - not enumerated ``` ## 1. writable - "can the value be changed" ```javascript const user = {}; Object.defineProperty(user, 'age', { value: 25, writable: false }); user.age = 30; // has no effect console.log(user.age); // 25 ``` - `writable: true` -> the value can be changed - `writable: false` -> the property is **read-only** ## 2. enumerable - "should the property show up during enumeration" ```javascript const user = {}; Object.defineProperty(user, 'secret', { value: '12345', enumerable: false }); console.log(user.secret); // accessible directly console.log(Object.keys(user)); // [] (not visible) for (const key in user) console.log(key); // nothing ``` - `enumerable: true` -> the property is visible in `for...in`, `Object.keys()`, `JSON.stringify()` - `enumerable: false` -> a "hidden" property A real-world example: built-in methods (`toString`, `valueOf`) have `enumerable: false` so they do not get in the way during enumeration. ## 3. configurable - "can it be deleted or have its flags changed" ```javascript const user = {}; Object.defineProperty(user, 'id', { value: 10, configurable: false }); delete user.id; // will not be deleted console.log(user.id); // 10 // Try to change writable: Object.defineProperty(user, 'id', { writable: true }); // TypeError: Cannot redefine property: id ``` - `configurable: true` -> the property can be deleted or its flags changed - `configurable: false` -> it cannot be deleted, and **cannot be changed** for `enumerable` / `configurable` / `writable: false -> true` > The only thing that can be changed is `writable: true -> false`, > but not the other way around. ## How to get the flag values ```javascript const obj = { name: 'Tim' }; const descriptor = Object.getOwnPropertyDescriptor(obj, 'name'); console.log(descriptor); ``` Outputs: ```javascript { value: 'Tim', writable: true, enumerable: true, configurable: true } ``` ## How to set flags ```javascript Object.defineProperty(obj, 'prop', { value: 42, writable: false, enumerable: true, configurable: false }); ``` ## Summary | Flag | Purpose | Example | |---|---|---| | `writable` | Whether the property's value can be changed | `user.age = 30` | | `enumerable` | Whether the property is visible during enumeration | `Object.keys(user)` | | `configurable` | Whether the property can be deleted or redefined | `delete user.prop` |For the reviewerNote to the moderator (optional)Visible only to the moderator. Helps review go faster.