JS: Property Attributes, writable, enumerable, configurable

By Xah Lee. Date: . Last updated: .

Property Attributes

Each property has associated info called attribute.

ECMAScript® 2016 Language Specification#sec-property-attributes

For data property, their attributes are:

Data Property Attributes
attribute namemeaning
value The property's value.
writable When true, the property's value can be changed.
enumerable When true, the property shows in some loop constructs, such as for-in Loop. [see JS: Access Property]
configurable If false, attempts to delete the property, change the property to be an accessor property, or change its attributes (other than [[Value]], or changing [[Writable]] to false) will fail.

For accessor property's attributes, see: JS: Getter/Setter Properties.

[see JS: Property Overview]

Show Property Attributes

[see JS: Object.getOwnPropertyDescriptor]

[see JS: Reflect.getOwnPropertyDescriptor]

Create/Modify Property Attributes

[see JS: Object.defineProperty]

Create/Modify Multiple Properties

[see JS: Object.defineProperties]

Checking Property's Enumerable Attribute

One convenient function is obj.propertyIsEnumerable(p).

This is convenient if you just want to check a property's enumerable attribute.

[see JS: Object.prototype.propertyIsEnumerable]

Accessor Property's Attributes

Note: Accessor properties don't have “writable” nor “value” attribute. But getter property has a “getter” attribute, and setter property has a “setter” attribute. Their values are functions.

[see JS: Getter/Setter Properties]

JS Object Property Topic

  1. JS: Property Overview
  2. JS: Property Key
  3. JS: Property Dot Notation / Bracket Notation
  4. JS: Create/Delete Property
  5. JS: Get Property, Set Property
  6. JS: Check Property Existence
  7. JS: Access Property
  8. JS: Property Attributes, writable, enumerable, configurable
  9. JS: Getter/Setter Properties
  10. JS: Property Descriptor
Liket it? Put $5 at patreon.

Or, Buy JavaScript in Depth

Ask me question on patreon