liveBook · Manning

Data property

As explained in JavaScript in Depth

A property whose descriptor stores a value directly and may include a writability flag.

A data property stores its value directly in a descriptor’s [[Value]] attribute: reading returns that stored value, and assignment replaces it when [[Writable]] permits. It contrasts with an accessor property, whose [[Get]] and [[Set]] functions compute or modify values. These descriptor pairs are mutually exclusive. section 5.2.1 section 5.2

The descriptor attributes explain behavior that otherwise looks like a runtime bug:

  • [[Writable]] controls whether the stored value can change; a failed assignment silently does nothing in sloppy mode and throws in strict mode. section 5.2.3
  • [[Enumerable]] controls visibility in for...in loops and Object.keys(), without preventing direct access. section 5.2.3
  • [[Configurable]] controls deletion and later descriptor changes; it is distinct from [[Writable]]. section 5.2.3
  • Object literals default these descriptor flags to true, whereas Object.defineProperty() defaults unspecified flags to false. section 5.2.3

A stored value that refuses assignment

const drawer = {}; Object.defineProperty(drawer, 'internalId', { value: 12345, writable: false, enumerable: false }); drawer.internalId = 54321; The property still reads as 12345 and does not appear in Object.keys(drawer). Object.getOwnPropertyDescriptor(drawer, 'internalId') exposes its value and controlling flags.

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
✓
✓

Compare the descriptor attributes that apply to data properties with those reserved for accessor properties. section 5.2

How JavaScript in Depth covers it

How deep it goes
Explains [[Value]], [[Writable]], [[Enumerable]], and [[Configurable]], while distinguishing language semantics from V8 storage mechanisms.
Examples
Uses drawer objects, Object.defineProperty(), descriptor inspection, and class fields contrasted with prototype accessors.
What you can do after
Diagnose property behavior with Object.getOwnPropertyDescriptor() and configure stored values using Object.defineProperty().
How it connects
Connects data properties to accessor properties, property descriptors, Object.defineProperty(), classes, and prototype behavior.

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.