Object.assign(target, source): Copies the values of all enumerable properties from one or more source objects to a target object. It returns the target object.
Object.freeze(obj): Freezes an object, preventing new properties from being added or existing properties from being removed or reconfigured.
const obj = { name: 'Khabib' };
Object.freeze(obj);
obj.name = 'Bob'; // This won't change the value
console.log(obj.name); // Output: 'Khabib'
Object.seal(obj): Seals an object, preventing new properties from being added, but allowing existing properties to be modified.
const obj = { name: 'Alice' };
Object.seal(obj);
obj.name = 'Bob'; // This will update the value
obj.age = 25; // This won't add a new property
console.log(obj); // Output: { name: 'Bob' }
Object.create(proto): Creates a new object with the specified prototype object and properties.
Object.hasOwn(obj, prop): Returns true if the specified object has the specified property as its own property, even if the property's value is undefined.
Object.hasOwnProperty(prop): Determines if an object contains the specified property as a direct property of that object and not inherited through the prototype chain.
I am a Full-Stack Developer specialized Front-end Developer. Passionate about algorithms, data structures, and coding challenges & always ready to face new challenges.
Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.
A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!
On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.
Top comments (2)
This is a really helpful overview of JavaScript object methods! It's great to have all the common ones in one place with clear explanations.
thank you.