Immutability Using Object Seal in Javascript
What if you want to allow changing props of an object, but do not want anyone to add new props? Well, that is what Object.seal is for. Objects in Javascript cannot be made immutable by using a const keyword. const works on primitives. It can also make sure you don’t reassign value to an object. const fruit = "apple"; fruit = "orange"; // TypeError: Assignment to constant variable. const fruit = { name: "apple" }; fruit = { name: "orange" }; //TypeError: Assignment to constant variable. But, const cannot prevent value in object from being changed. ...