liveBook · Manning

Property descriptor

As explained in JavaScript in Depth

An object that describes a property’s attributes such as writability, enumerability, configurability, or getter/setter behavior.

A property descriptor explains why an assignment silently fails, why a property vanishes from Object.keys(), or why delete does nothing. It records how a property stores or computes values and whether that behavior may be changed. section 5.2 section 5.2.3

Descriptors divide properties into two mutually exclusive forms:

  • Data properties store a value through [[Value]] and may permit replacement through [[Writable]]. section 5.2 section 5.2.1
  • Accessor properties compute reads with [[Get]] and handle writes with [[Set]]; they cannot also use [[Value]] or [[Writable]]. section 5.2
  • [[Enumerable]] controls appearance in for...in and Object.keys(), while [[Configurable]] controls deletion and later descriptor changes. section 5.2.3
  • Object literals default descriptor flags to true, whereas Object.defineProperty() defaults omitted flags to false. section 5.11 section 5.2.3

Diagnosing a locked property

const drawer = {}; Object.defineProperty(drawer, 'serialNumber', { value: 'SN-12345', writable: false, enumerable: true, configurable: false, }); drawer.serialNumber = 'SN-99999'; delete drawer.serialNumber; The assignment silently fails in sloppy mode but throws in strict mode; delete also fails because the property is non-configurable. Object.getOwnPropertyDescriptor(drawer, 'serialNumber') exposes these settings. section 5.2.3

Table 5.1 The property descriptor attributes and the property types they apply to:
Name
Description
Data Properties
Accessor Properties
[[Value]]
A stored JavaScript value
✓
 
[[Writable]]
A boolean indicating whether [[Value]] can be changed
✓
 
[[Get]]
Code used to compute the property value
 
✓
[[Set]]
Code used to modify the property value
 
✓
[[Enumerable]]
A boolean indicating whether the property can appear in iterations
✓
✓
[[Configurable]]
A boolean indicating whether the property descriptor itself can be changed or deleted
✓
✓

Use the attribute matrix to distinguish data and accessor properties and to map each internal attribute to its permitted property type. section 5.2

How JavaScript in Depth covers it

How deep it goes
Explains internal attributes, defaults, APIs, accessor distinctions, and strict-mode effects, but stops short of runtime storage internals.
Examples
Uses drawer objects, locked serial numbers, hidden internal identifiers, and getter/setter-backed contents.
What it assumes
Assumes JavaScript object and property syntax while teaching data access, accessors, descriptor attributes, and definition APIs.
What you can do after
Diagnose/debug surprising assignments, iteration omissions, deletions, and redefinitions with descriptor inspection and configuration.
How it connects
Connects data properties, accessor properties, Object.defineProperty(), Object.getOwnPropertyDescriptor(), strict mode, and sloppy mode.

Also explained in

Compare how 3 books explain property descriptor →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of JavaScript in Depth. The section links point to the parts of the book it draws on.