JS: Property Descriptor

By Xah Lee. Date: . Last updated: .

What is Property Descriptor

Property Descriptor is the syntax for specifying Property Attributes . It has the form:

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

Property Descriptor for Getter Property

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

[see Getter Setter Properties]

Property Descriptor for Setter Property

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

Get Property Descriptor

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

Set Property Descriptor

Default Values of Property Descriptor

value
undefined
configurable
false
enumerable
false
writable
false
set
undefined
get
undefined
// check default values of property attributes

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

const defaultX = new Map(
[ ["value", 1],
["writable", false],
["enumerable", false],
["configurable", false] ]);

console.log(
 Object.entries ( desc ) . every (([k,v]) => (v === defaultX.get(k)))
);
// true

JavaScript, Property

BUY Ξ£JS JavaScript in Depth