Preventing Object Modification in Javascript


Prevent modifications to an object using Object.freeze.

Source Code

let obj = { name: 'John' };
Object.freeze(obj);
obj.name = 'Jane'; // This will not work
console.log(obj);
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments