To make an object immutable, you can use Object.freeze(), or to prevent adding or removing properties, you can use Object.seal().
Object.freeze();
This method makes the object completely immutable.
const obj = Object.freeze({ name: 'John' });
obj.name = 'David';
console.log(obj.name);
Result: The name property cannot be changed.
Object.seal();
This method prevents adding new properties and deleting existing ones, but you can still change the values of the existing properties.
const obj = Object.seal({ name: 'John' });
obj.name = 'David';
obj.age = 30;
delete obj.name;
console.log(obj.name);
console.log(obj.age);
Result: The name can be changed, but age can't be added or name deleted.