How to stop adding, modifying and deleting an object’s properties?

In JavaScript, we can use the freeze() method of Object to stop adding, modifying, and deleting an object’s properties. The freeze() method will only allow us to read properties. It will not allow adding, modify and delete operations to the object.

Following is the code sample:

const userObj = {
    name: 'Joe Smith',
    gender: 'Male',
    age: 40
}

Object.freeze(userObj);
userObj.age = 50;
console.log(userObj);