Property Attributes: Writable, Configurable
What you'll learn: How the writable and configurable attributes control what you can do with an object's properties.
The Core Idea
Every property on an object has hidden attributes that act like permission flags. Two critical ones are:
writable: Can you reassign the property's value?configurable: Can you delete the property or change its attributes?
These attributes default to true when you create properties normally, but you can customize them with Object.defineProperty().
Writable: Permission to Reassign
When writable is false, attempts to change the property's value fail silently (or throw an error in strict mode):
const user = {};
Object.defineProperty(user, 'id', {
value: 42,
writable: false
});
user.id = 99; // Fails silently (or throws in strict mode)
console.log(user.id); // 42 (unchanged)
Analogy: A read-only file on your computer — you can view it, but you can't edit it.
Configurable: Permission to Delete or Redefine
When configurable is false, you cannot delete the property or change its attributes:
const settings = {};
Object.defineProperty(settings, 'apiKey', {
value: 'secret',
configurable: false
});
delete settings.apiKey; // Fails silently
console.log(settings.apiKey); // 'secret' (still there)
// Also can't change attributes anymore:
// Object.defineProperty(settings, 'apiKey', { writable: true }); // TypeError
Analogy: A permanent marker on a whiteboard — once it's there, you can't erase or modify it.
When Both Are False
The property becomes completely locked — you can't change its value, delete it, or reconfigure it. This is effectively a permanent constant.
Key Takeaway: writable controls whether you can reassign a property's value, while configurable controls whether you can delete it or change its descriptor attributes. Use these to enforce immutability or protect critical properties.