JavaScript

Object Methods

Master JavaScript object methods! Learn Object.assign, Object.freeze, Object.create, Object.fromEntries, hasOwnProperty, advanced destructuring, and more.

By TechCoder TeamLast updated: 2026-06-02
In a Nutshell

Master JavaScript object methods! Learn Object.assign, Object.freeze, Object.create, Object.fromEntries, hasOwnProperty, advanced destructuring, and more. This hands-on tutorial focuses on practical implementation of object methods concepts.

Object Methods Deep Dive πŸ—οΈ

This lesson covers the complete toolkit of static Object methods β€” each briefly explained β€” plus advanced patterns for working with objects in modern JavaScript.


1. Merging & Copying Methods πŸ”—

These methods help you combine or copy objects.

MethodWhat it does
Object.assign(target, ...sources)Copies own enumerable properties from sources into target. Shallow copy
{...obj} (Spread)Spreads object into a new object literal β€” cleaner than Object.assign for copies
structuredClone(obj)Creates a deep clone β€” nested objects are fully copied (built-in, modern)
JAVASCRIPT PLAYGROUND
⏳ Loading editor…

2. Conversion Methods πŸ”„

These methods convert objects to/from other structures.

MethodWhat it does
Object.keys(obj)Returns array of the object's own property names
Object.values(obj)Returns array of the object's own property values
Object.entries(obj)Returns array of [key, value] pairs
Object.fromEntries(iterable)Creates an object from [key, value] pairs β€” reverse of entries
JAVASCRIPT PLAYGROUND
⏳ Loading editor…

3. Immutability Methods πŸ”’

These methods control whether an object can be changed.

MethodWhat it does
Object.freeze(obj)Makes the object completely immutable β€” no adds, updates, or deletes
Object.seal(obj)Prevents adding/deleting but allows updating existing properties
Object.isFrozen(obj)Returns true if the object is frozen
Object.isSealed(obj)Returns true if the object is sealed
JAVASCRIPT PLAYGROUND
⏳ Loading editor…

4. Prototype & Inspection Methods πŸ”¬

These methods work at the prototype chain level.

MethodWhat it does
Object.create(proto)Creates a new object with a specified prototype
Object.getPrototypeOf(obj)Returns the prototype of an object
Object.getOwnPropertyNames(obj)Returns all own property names, including non-enumerable
Object.defineProperty(obj, key, descriptor)Defines a property with fine-grained control over writability, enumerability, etc.
JAVASCRIPT PLAYGROUND
⏳ Loading editor…

5. Property Ownership Methods πŸ§ͺ

These check whether a property belongs directly to an object (not inherited).

MethodWhat it does
Object.hasOwn(obj, key)Returns true if the object directly has the property β€” preferred modern approach
obj.hasOwnProperty(key)Same as above but an instance method β€” can be shadowed, so less safe
key in objReturns true if key exists anywhere on the prototype chain (includes inherited)
JAVASCRIPT PLAYGROUND
⏳ Loading editor…

6. Advanced Destructuring Patterns 🎯

Destructuring is the modern way to extract values from objects.

PatternWhat it does
const { a, b } = objBasic extraction
const { a: alias } = objExtract and rename to a new variable name
const { a = default } = objExtract with a default value if property is missing
const { a, ...rest } = objExtract a and collect everything else into rest
const { outer: { inner } } = objDestructure nested objects
JAVASCRIPT PLAYGROUND
⏳ Loading editor…

Practical Example: API Response Normaliser 🌐

JAVASCRIPT PLAYGROUND
⏳ Loading editor…

AI Mentor

Confused about "JavaScript object methods: Object.assign, freeze, seal, create, fromEntries, hasOwn, structuredClone and advanced destructuring"? Ask our AI mentor for a simplified explanation.

Quiz

Quiz

Question 1 of 5

What is the difference between Object.freeze() and Object.seal()?

They are the same
freeze() prevents all changes; seal() prevents add/delete but allows updates
seal() prevents all changes; freeze() allows updates only
freeze() only works on arrays

Key Takeaways

βœ… Merge: Object.assign or spread {...obj} β€” both shallow.
βœ… Deep clone: structuredClone(obj) β€” copies nested objects fully.
βœ… Convert: Object.entries + Object.fromEntries β€” transform objects like arrays.
βœ… Immutability: freeze() (no changes) vs seal() (no add/delete).
βœ… Ownership: Object.hasOwn β€” check direct properties safely.
βœ… Destructuring: rename, defaults, rest, and nested in one step.

What's Next?

You've mastered objects! Next, see how JSON is used to send objects across the web.

Keep coding! πŸš€