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:

  1. writable: If true, the property can be changed.
  2. enumerable: If true, the property shows up in loops (like for..in).
  3. 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.