Question presented to candidate: "You have an object built with Object.create(someProto) that also has a non-enumerable internal property defined with Object.defineProperty. If you call Object.keys, Object.values, and Object.entries on it, exactly what shows up and what gets left out?"
What a strong answer should cover:
Object.keys(obj),Object.values(obj), andObject.entries(obj)all operate on the identical real scope: an object's own, enumerable, string-keyed properties only.- 📌 Verified, not assumed: a real object with an inherited property AND a real non-enumerable own property genuinely excluded both from all three methods' output — only the genuinely own-and-enumerable properties appeared.
- 📌 Interview term:
Object.fromEntries()— reversesentries()back into a real object, useful for transforming data with.map()/.filter()on the entries array and rebuilding. Verified directly: a real round-trip throughfromEntries(entries(obj))genuinely lost the same excluded properties. - A precise answer names the real, verified key-ordering rule that applies to all three: real integer-like keys come first in ascending numeric order, then real string keys in original insertion order, then real Symbol keys last (and Symbols are excluded from all three of these specific methods entirely — verified directly, they need
Object.getOwnPropertySymbols()instead). - The precise, honest scope: these three methods were not always available together —
Object.keysshipped in ES5, whileObject.values/Object.entriesshipped later, in ES2017.
Clarifying questions expected:
- "Does the actual downstream code need Symbol-keyed properties too, or only string-keyed ones?" — all three of these specific methods genuinely, deliberately exclude Symbols.
- "Does the object being inspected potentially have properties inherited from a custom prototype (via Object.create or a class), which these methods will correctly, genuinely skip?"
Code / implementation expected: Yes — a real object combining an inherited property, a non-enumerable own property, and normal own properties, run through all three methods with the actual output shown, is the concrete, convincing proof of exactly what is included and excluded.