Sealing JavaScript Objects using Object.seal()

JavaScript provides a method Object.seal() which seals an object, preventing new properties from being added to it and marking all existing properties as non-configurable. Values of existing properties can still be changed if they are writable. Let’s see an example: var employee = { name: "John Doe", role: "Developer" }; Object.seal(employee); (function() { "use strict"; … Continue reading Sealing JavaScript Objects using Object.seal()

Freezing JavaScript objects with Object.freeze()

In JavaScript, objects are used to store keyed collections of various data and more complex entities. Objects penetrate almost every aspect of the JavaScript language. The object might be accessed as global or passed as an argument. Functions that have access to the object can modify the object, whether intentionally or accidentally. To prevent modification … Continue reading Freezing JavaScript objects with Object.freeze()