JS: Property Descriptor

By Xah Lee. Date: . Last updated: .

What is property descriptor

Property Descriptor is the syntax for specifying Property Attributes.

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

syntax

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

Property Descriptor for Getter Property

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

Property Descriptor for Setter Property

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

Get property descriptor

Set property descriptor

Default values of property descriptor

// check default values of property descriptor

const jj = Object.create(Object.prototype, { dog: {} });
const xdesc = Reflect.getOwnPropertyDescriptor(jj, "dog");

console.assert(xdesc.value === undefined);
console.assert(xdesc.writable === false);
console.assert(xdesc.enumerable === false);
console.assert(xdesc.configurable === false);

console.assert(xdesc.get === undefined);
console.assert(xdesc.set === undefined);