Hidden Property Settings
Usually, an object's property is just a value. But actually, every property has " hidden " flags that dictate its behavior.
Three Main Flags:
- writable: If
true, the property can be changed. - enumerable: If
true, the property shows up in loops (likefor..in). - configurable: If
true, the property can be deleted and its flags can be modified.
let user = { name: "John" };
Object.defineProperty(user, "name", {
writable: false // Now the name cannot be changed!
});
Important
If configurable: false, you can never change it back to writable: true or delete it. It's a one-way street.
Note
Built-in properties (like toString) have the enumerable: false flag by default, so they don't get in the way of your loops.