Preventing modification of Objects
There are many ways to lock an object according to your needs.
The process of object freezing proves valuable in the representation of logically immutable data structures, particularly when altering object properties could potentially result in adverse effects within your application. It's noteworthy that the application of Object.freeze(…) is limited to a shallow level. Consequently, object values within a frozen object remain susceptible to mutation.
Object.seal extends the functionality of Object.preventExtensions by not only preventing the addition of arbitrary properties to objects but also by prohibiting the modification of attributes associated with existing properties. Furthermore, Object.seal disallows the deletion of properties altogether.Syntax
The utilization of Object.preventExtensions() involves setting the extensible attribute of the object 'o' to false, effectively preventing the addition of new properties to it. This alteration is irreversible, as once an object's extensibility has been revoked, it cannot be reconfigured to be extensible again.example
Object modification can be prevented using methods like Object.freeze(), which makes objects effectively immutable by disallowing addition, removal, or alteration of properties. Object.preventExtensions() stops the addition of new properties while maintaining existing ones, while Object.seal() goes a step further by prohibiting both addition and modification of properties.