JS: Property Descriptor

By Xah Lee. Date: . Last updated: .

Property Descriptor is the syntax for setting and displaying property's attributes. It has the form:

{ value: value, writable: boolean, enumerable: boolean, configurable: boolean }

〔►see JS: Property Attributes

Property Descriptor is used by several JavaScript functions to create/set properties together with attributes. For example,

and some function returns a property descriptor:

Property Descriptor for Getter Property

Property Descriptor for getter property is:

{ get: function, enumerable: boolean, configurable: boolean }

〔►see JS: Getter/Setter Properties

Property Descriptor for Setter Property

Property Descriptor for setter property is:

{ set: function, enumerable: boolean, configurable: boolean }

Default Values of Property Descriptor

Property Descriptor default values:

//  default values of property attributes

let xx = Object.create( Object.prototype, { "p":{value:1} } );

console.log(  Object.getOwnPropertyDescriptor(xx, "p") );
// prints
// { value: 1,
//   writable: false,
//   enumerable: false,
//   configurable: false }

ECMAScript 2015 §ECMAScript Data Types and Values#table-4

Reference

ECMAScript® 2016 Language Specification#sec-property-descriptor-specification-type

JS Object Property Topic

  1. JS: Property Overview
  2. JS: Property Key
  3. JS: Property Dot Notation / Bracket Notation
  4. JS: Create/Delete Property
  5. JS: Get Property, Set Property
  6. JS: Check Property Existence
  7. JS: Access Property, List Properties
  8. JS: Property Attributes
  9. JS: Getter/Setter Properties
  10. JS: Property Descriptor
Like what you read? Buy JavaScript in Depth