Understanding the data properties and accessor properties

Since ES5, every object property is either a data property or an accessor property. A data property has a value, which may or may not be writable, whereas an accessor property has a getter-setter pair of functions to set and retrieve the property value.

The attributes of a data property are value, writable, enumerable, and configurable. On the other hand, the attributes of an accessor property are set, get, enumerable, and configurable.

A descriptor is an object that describes the attributes of a property. When creating a property using the Reflect.defineProperty() method, the Object. defineProperty() method, the Object.defineProperties() method, or the Object.create() method, we need ...

Get Learn ECMAScript - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.