You can prevent an object from being extended (i.e., from adding new properties) using the Object.preventExtensions()
method. This method makes the object non-extensible.
Example:
const obj = { name: 'John' };
Object.preventExtensions(obj);
obj.age = 30; // Won't be added
console.log(obj); // { name: 'John' }
Tags: basic, JavaScript, objects
URL: https://www.tiktok.com/@jsmentoring/photo/7463226904930258209