Object Freeze vs Object Seal In Javascript

Опубликовано: 05 Октябрь 2024
на канале: 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


На этой странице сайта вы можете посмотреть видео онлайн Object Freeze vs Object Seal In Javascript длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь infinitech 05 Октябрь 2024, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 226 раз и оно понравилось 7 зрителям. Приятного просмотра!