Object.getOwnPropertyDescriptorsintermediate// Inspect all property descriptors at once
const obj = { a: 1, b: 2 }
Object.getOwnPropertyDescriptors(obj)
// β { a: { value: 1, writable: true, ... }, b: { value: 2, ... } }Use Object.getOwnPropertyDescriptors() to get all property descriptors of an object, useful when doing a complete clone.
Unlike Object.keys or Object.entries, getOwnPropertyDescriptors includes non-enumerable properties.
Challenge: Implement countAllDescriptors(obj) that returns the total number of own properties (including non-enumerable).
// obj has 1 enumerable + 1 non-enumerable
countAllDescriptors(obj) // β 2