liveBook · Manning

Set

As explained in JavaScript in Depth

A JavaScript collection that stores unique values and retains its entries until they are removed or otherwise released.

Here, set denotes the property-access mechanism that modifies a value, not a collection. JavaScript distinguishes data properties, which store values directly, from accessor properties, whose [[Set]] attribute supplies code for modifying a value. section 5.2

A setter belongs to an accessor property's descriptor and is mutually exclusive with [[Value]]. A data property instead uses [[Writable]] to determine whether assignment can change its stored value. section 5.2 section 5.2.3

Accessor assignment

An object can expose contents through get and set functions: assigning drawer.contents invokes the setter, which updates _contents; reading drawer.contents invokes the getter. Its descriptor reports get and set functions, but no value.

Do not confuse set with writability. Assigning to a non-writable data property silently fails in sloppy mode and throws in strict mode, while configurable controls deletion and descriptor changes. section 5.2.3

How JavaScript in Depth covers it

How deep it goes
Distinguishes descriptor attributes and assignment modes, but stops short of broader runtime implementation details.
Examples
Uses drawer.contents to demonstrate getter and setter functions, descriptor inspection, and private backing storage.
What it assumes
Assumes familiarity with JavaScript objects and assignments while defining data, accessor, and descriptor terminology.
What you can do after
Diagnose assignment behavior by inspecting descriptors and distinguishing setters from writable data properties.
How it connects
Connects set with accessor properties, data properties, property descriptors, writable, enumerable, and configurable.

Also explained in

Compare how 19 books explain set →

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.