Course contentsShow
← JavaScript
Lesson 609 of 2,72315. ObjectsFree lesson

Property Descriptors: Writable, Enumerable, Configurable

Understand the hidden attributes that control how properties behave.

Property Descriptors: Writable, Enumerable, Configurable

You'll learn about the hidden attributes that control how object properties behave behind the scenes.

The Hidden Settings

When you create a property on an object, JavaScript doesn't just store the value—it also attaches three boolean flags that control the property's behavior:

  • writable: Can the value be changed?
  • enumerable: Will the property show up in loops like for...in?
  • configurable: Can the property be deleted or its descriptor changed?

By default, when you create properties normally (like obj.name = "Alice"), all three are set to true. But you can control these flags explicitly.

Seeing and Setting Descriptors

JavaScript provides Object.getOwnPropertyDescriptor() to inspect these flags and Object.defineProperty() to set them:

const person = { name: "Alice" };

// Check the descriptor
console.log(Object.getOwnPropertyDescriptor(person, 'name'));
// { value: 'Alice', writable: true, enumerable: true, configurable: true }

// Create a read-only property
Object.defineProperty(person, 'id', {
  value: 12345,
  writable: false,      // Cannot be changed
  enumerable: true,
  configurable: false   // Cannot be deleted
});

person.id = 99999;      // Silently fails (or throws in strict mode)
console.log(person.id); // 12345

delete person.id;       // Fails silently
console.log(person.id); // 12345

Real-World Analogy

Think of a property like a file on your computer. The value is the file's content, writable is whether you have write permissions, enumerable is whether it shows up in directory listings, and configurable is whether you can delete it or change its permissions.

Key Takeaway: Every property has three hidden flags—writable, enumerable, and configurable—that control how it can be modified, accessed, and listed.