Object.defineProperty (writable/enumerable/configurable)

Three switches on every property: writable, enumerable, configurable. What does defineProperty set for the switches left out, and what happens to a refused…

Why it matters

"Why won’t the value change?" and "why isn’t it in Object.keys or JSON?" are puzzling bugs until you know these switches. Much of the language uses them: class methods are not enumerable, Object.freeze turns writable and configurable off, and libraries use defineProperty for read-only or hidden properties.

The key idea

defineProperty turns off the switches it is not told about; a literal turns them on

Common mistakes

Try it in this playground