Using Object.seal to Prevent Adding or Removing Properties in Javascript


Prevent adding or removing properties from an object, but allow modification of existing properties.

Source Code

let obj = { name: 'John' };
Object.seal(obj);
obj.age = 30; // Cannot add new properties
console.log(obj);
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments