- The source code examples in this post are on github
1.2 - The object freeze static method
The object freeze static method can be used to freeze an object all together. Once an object is frozen the values can not be changed, no new properties can be added or removed, and all other properties of the object can also not be changed.
When freezing an object only the top level properties will be frozen, any property of the object that is a nested object can still be mutated. So if that is a problem then you will want to do a deep freeze which would be looping over all the nested objects of an object and freezing them also.
1.3 - The object seal method
The object seal static method is similar to object freeze in the sense that a sealed object can not have any additional properties added, but any properties that existed before hand can still be changed.
1.4 - The object define property method
There is then the define property method of the main Object global. This method can be used to set a writable flag for a property when defining it. So then this method is yet another tool in the toolbox when it comes to defining the nature of an object, and can also be used to obtain a similar result. The define property is worth looking into more if you have not done so all ready and not just for the sake of making an object property writable or not. It can also be used to make private object properties that will not show up when looping over the public keys by using a for in loop or something like the Object.keys static method.
This define property method then might prove to be a better option because I can also use it to set if a property can be writable or not, and also set some additional property for the object properties also while I am at it.
2 - Conclusion
So the object freeze method can be used to freeze the state of an object, but you still might want to deep freeze the object if it has nested properties. However if you really need to use the object freeze method then maybe you should really take a deeper look at what is going on in your code. One line of reasoning is that yes there is the const keyword, and there are also these additional object methods that can be used in conjunction with the const keyword. However still you can declare an object with just plain old var also, and as long as you treat it as a constant in your code then the same result is accomplished.