JavaScript objects come with a set of static methods that let you inspect, create, copy, freeze, and iterate over objects. This is a practical reference for every Object.* method you'll reach for in interviews and real code.
1. Object.keys(obj) — Get Own Enumerable Keys
Returns an array of an object's own enumerable string-keyed property names.
Loading editor...
Interview use: Iterating over object properties, counting keys for deep comparison, filtering keys in deepOmit.
2. Object.values(obj) — Get Own Enumerable Values
Returns an array of values (same order as Object.keys).
Loading editor...
3. Object.entries(obj) — Get [key, value] Pairs
Returns an array of [key, value] pairs. Useful for iterating with destructuring.
Loading editor...
Interview use: classnames() conditionally adds keys when values are truthy; listFormat style transformations.
4. Object.fromEntries(entries) — Array → Object
The reverse of Object.entries. Converts an iterable of [key, value] pairs into an object.
Loading editor...
5. Object.assign(target, ...sources) — Copy Properties
Copies own enumerable properties from source objects to a target. Returns the target.
Loading editor...
Interview use: Merging default options, shallow cloning, overriding configs.
6. Object.create(proto, descriptors?) — Create with Custom Prototype
Creates a new object with the specified prototype and optional property descriptors.
Loading editor...
Interview use: Creating dictionaries without inherited properties (Object.create(null)), setting up prototype chains explicitly.
7. Object.freeze(obj) & Object.seal(obj) — Immutability
- freeze: No additions, deletions, or modifications.
writablebecomesfalse,configurablebecomesfalse. - seal: No additions or deletions, but existing properties can be modified.
configurablebecomesfalse.
Loading editor...
Interview use: Ensuring configuration objects aren't mutated accidentally.
8. Object.defineProperty(obj, key, descriptor) — Precise Control
Define or modify a property with fine-grained control over writability, enumerability, and configurability.
Loading editor...
9. Object.prototype.hasOwnProperty(key) — Own Property Check
Checks if a property exists directly on the object, not on the prototype chain.
Loading editor...
Interview use: Deep equality checks, filtering prototype properties during iteration.
10. Object.prototype.toString.call(value) — Reliable Type Check
Returns [object Type] — the most reliable way to determine a value's internal type.
Loading editor...
Interview use: Type utilities (#5), distinguishing arrays from plain objects, cross-realm type checking.
Quick Reference
| Method | What It Does |
|---|---|
Object.keys(o) | Array of own enumerable string keys |
Object.values(o) | Array of own enumerable values |
Object.entries(o) | Array of [key, value] pairs |
Object.fromEntries(arr) | Array of pairs → object |
Object.assign(t, ...s) | Copy own properties into target |
Object.create(proto) | New object with given prototype |
Object.freeze(o) | Make immutable (shallow) |
Object.seal(o) | Prevent add/delete, allow modify |
Object.isFrozen(o) | Check frozen status |
Object.isSealed(o) | Check sealed status |
Object.defineProperty(o, k, d) | Precise property definition |
Object.hasOwn(o, k) | Own-property check (modern) |
Object.getPrototypeOf(o) | Get [[Prototype]] |
Object.getOwnPropertyNames(o) | All own keys (including non-enumerable) |
Object.prototype.hasOwnProperty.call(o, k) | Safe own-property check |
Object.prototype.toString.call(v) | Reliable type tag |