Object Freeze vs Object Seal In Javascript

Published: 05 October 2024
on channel: infinitech
226
7

In JavaScript, Object.freeze() and Object.seal() are two methods used to control modifications to objects, but they differ in what they restrict. Here's a breakdown:

Object.freeze()

Purpose:
Makes an object immutable, meaning neither the object’s properties nor their values can be changed.

Effect:
Prevents adding new properties.
Prevents deleting existing properties.
Prevents modifying the values of existing properties.
Prevents changing the enumerability, configurability, or writability of existing properties.

Object.seal()

Purpose:
Prevents the addition or deletion of properties, but allows modifying the existing properties.

Effect:
Prevents adding new properties.
Prevents deleting existing properties.
Allows modifying the values of existing properties (as long as they are writable).

These methods are useful when you need to lock down an object to varying degrees of immutability.

#javascript #javascripttutorial #javascriptprojects
#javascripttutorialhindi


On this page of the site you can watch the video online Object Freeze vs Object Seal In Javascript with a duration of hours minute second in good quality, which was uploaded by the user infinitech 05 October 2024, share the link with friends and acquaintances, this video has already been watched 226 times on youtube and it was liked by 7 viewers. Enjoy your viewing!