Object Properties

Object properties may hold any kind of value, including primitive values and object instances. The ECMAScript specification defines two kinds of properties: data properties and accessor properties. Data properties store a data value at a single location. You can directly read or write the location where the data value is stored.

In contrast, accessor properties do not contain a data value, but they are a combination of two methods. The getter method is responsible for obtaining the value of the property; the setter method takes care to write the property value. Internally, JavaScript assigns attributes to properties and those attributes determine the behavior of the property, including the type of operations available on that specific property.

Both data and accessor properties have two common attributes, Configurable and Enumerable. Configurable indicates whether the property may be redefined by removing the property, changing the property’s attributes, or changing the property into an accessor property. Enumerable designates whether the property will be returned in a for-in loop.

Get hands-on with 1200+ tech skills courses.