Learn to create Objects which cannot be Tampered
What is Tamper Proof Objects?
The most important thing about Tamper-proof Object is that once the operation is performed it cannot be reversed.
But this behaviour can be altered by making use of the preventExtensions() method, which ensures that no properties and methods are added to the object.
Even though no new properties or methods could be added to the, the exisiting properties and methods can be modified or deleted using the method isExtensible().
Another advanced way to create Tamper Proof Object is by creating what is called a " sealed object " .
A Sealed Object cannot be extended and existing object members have their [[Configurable]] attribute set as false.
What this does is, you cannot delete properties and methods as data properties cannot be altered to accessor properties, or vice versa via Object.defineProperty()
To seal an object make use of the method Object.seal(), to see if an object is sealed or not use the method Object.isSealed()
The most strictest form of tamper-proof object is called as a frozen object , these objects are both non extensible as well as sealed
Objects of this type have their data properties attribute [[Writable]] set as false , hence accessor properties can still be written to them , but only if a [[Set]] function has been defined.
The objects can be frozen by using the method Object.freeze(), to detect is the objects are frozen or not use the method Object.isFrozen()