JavaScript Runtime Semantics

Objects & Property Descriptors

JavaScript objects are collections of properties. Each property has a descriptor that defines whether it is a data property or accessor, and whether it is writable, enumerable, and configurable.
  • Objects are not just dictionaries
  • Property lookup checks own properties first, then prototypes
  • Descriptors control property behavior
  • Enumerability affects iteration and serialization
  • Freezing is shallow
Property descriptor fields
FieldMeaningApplies to
valueStored valueData property
writableCan value be changed?Data property
get / setAccessor functionsAccessor property
enumerableAppears in enumeration?Both
configurableCan redefine/delete?Both
Descriptor-defined property
const user = {}

Object.defineProperty(user, "id", {
  value: "u_123",
  writable: false,
  enumerable: true,
  configurable: false,
})

console.log(Object.keys(user)) // ["id"]
Descriptors explain behavior that normal property syntax hides.
Sources
  • MDN JavaScript Guide and ReferenceWorking with objects; enumerability and ownership
  • ECMAScript Language SpecificationObjects and property descriptors
  • The Modern JavaScript TutorialObject properties configuration