DEV Community

Cover image for Differences between Object.freeze( ) and Object.seal( ) in Javascript
Maria Antonella 🦋
Maria Antonella 🦋

Posted on

52 15

Differences between Object.freeze( ) and Object.seal( ) in Javascript

They are functions that may appear to do the same action but have significant differences. And it was difficult for me to learn it. I don't know why but they always confused me.

👉 Object.freeze(): It prevents you from adding new properties, removing existing properties and modifying them.

👉 Object.seal(): You can modify existing properties but you can't delete or add new ones.

CRUD Operations

If we differentiate them through the CRUD operations: Create - Read - Update - Delete, we obtain the following comparison.

                  Create     Read    Update     Delete
Object.freeze()    ❌        ☑️      ❌         ❌
Object.seal()      ❌        ☑️      ☑️         ❌

Enter fullscreen mode Exit fullscreen mode

The wonderful world of Javascript. That's all for today :)

Top comments (3)

Collapse
 
clamstew profile image
Clay Stewart

Sounds like a job for deep-freeze npmjs.com/package/deep-freeze

Collapse
 
clementdunstan profile image
clement dunstan siaffu

nice

Collapse
 
itays123 profile image
Itay Schechner

Whoa! That's fascinating!

SurveyJS custom survey software

JavaScript Form Builder UI Component

Generate dynamic JSON-driven forms directly in your JavaScript app (Angular, React, Vue.js, jQuery) with a fully customizable drag-and-drop form builder. Easily integrate with any backend system and retain full ownership over your data, with no user or form submission limits.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay