liveBook · Manning

Enumerable property

As explained in JavaScript in Depth

An internal attribute of a property descriptor that determines whether the property appears during enumeration.

A property can exist and remain directly accessible while disappearing from for...in loops and Object.keys(). The [[Enumerable]] descriptor attribute controls that visibility. section 5.2 section 5.2.3

Inspect the attribute with Object.getOwnPropertyDescriptor(). A false enumerable value hides the property from property lists without removing it or preventing direct access. The attribute applies to both data and accessor properties. section 5.2.3

A hidden internal identifier

Object.defineProperty(drawer, 'internalId', { value: 12345, writable: false, enumerable: false }); makes Object.keys(drawer) omit internalId, while drawer.internalId still returns 12345. The property is hidden from enumeration, not deleted.

Keep these descriptor behaviors distinct:

  • enumerable controls whether iteration exposes the property. section 5.2.3
  • writable controls whether a stored value can change. section 5.2.3
  • configurable controls whether the property can be deleted or its descriptor changed. section 5.2.3

How JavaScript in Depth covers it

How deep it goes
Defines the descriptor attribute, demonstrates inspection and hiding, and distinguishes enumeration from value mutation and deletion.
Examples
Uses a hidden internalId property and contrasts Object.keys() output with direct property access.
What you can do after
Diagnose missing properties with Object.getOwnPropertyDescriptor() and control enumeration with Object.defineProperty().
How it connects
Connects enumerable properties with property descriptors, data properties, accessor properties, for...in, Object.keys(), writable, and configurable.

Also explained in

Compare how 3 books explain enumerable property →

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.