JavaScript: Reflect.getOwnPropertyDescriptor

By Xah Lee. Date: . Last updated: .

New in JS2015.

Reflect.getOwnPropertyDescriptor( obj, key )
Return the Property Attributes. If the property doesn't exist, returns undefined. The return value is a Property Descriptor. If obj is not object, throw a TypeError exception.
const hh = {p:4};

console.log( 
 Reflect.getOwnPropertyDescriptor ( hh , "p" )
);
// { value: 4, writable: true, enumerable: true, configurable: true }

// non-exist key
console.log( 
 Reflect.getOwnPropertyDescriptor ( hh , "yyy" ) === undefined
);
// true

Object.getOwnPropertyDescriptor vs Reflect.getOwnPropertyDescriptor?

What's the difference?

Object.getOwnPropertyDescriptor( obj, key ) will first convert obj to object.

[see Object.getOwnPropertyDescriptor]

JS in Depth
XAH  BUY NOW

JS in Depth

JS Obj Ref

DOM


JS Obj Ref

Reflect