Property descriptors

When adding properties to objects in the conventional fashion, either via property access or via an object literal, the properties will be given the following implicit traits:

  • configurable: This means the property can be deleted from the object (and if its property descriptor can be changed)
  • enumerable: This means the property will be visible to enumerations such as for...in and Object.keys()
  • writable: This means the property's value can be changed via an assignment operator (such as obj.prop = ...)

JavaScript gives you the power to turn off these traits individually, but be wary that changes to these traits can obscure the behavior of your code. For example, if a property is described as not being writeable but a ...

Get Clean Code in JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.