JavaScript: Reflect.getOwnPropertyDescriptor

By Xah Lee. Date: . Last updated: .

New in JS2015.

Reflect.getOwnPropertyDescriptor(obj, key)
const jj = { p: 4 };

console.log(
  JSON.stringify(Reflect.getOwnPropertyDescriptor(jj, "p")) ===
    '{"value":4,"writable":true,"enumerable":true,"configurable":true}',
);

// non-exist key
console.log(
  Reflect.getOwnPropertyDescriptor(jj, "yy") === undefined,
);

Difference Between Object.getOwnPropertyDescriptor vs Reflect.getOwnPropertyDescriptor

JavaScript Define Properties

BUY ΣJS JavaScript in Depth