JavaScript Course
JavaScript
/
Advanced

Property Descriptors

Definition

Hidden configuration objects attached to every property in a JavaScript object that define its behavior (whether it is writable, enumerable, or configurable).

Explain Like I'm New

When you add a property to an object (`obj.name = 'Alice'`), JS secretly creates a control panel for that property. Property Descriptors are how you open that control panel and flip switches, like making a property completely un-deletable or invisible to `for...in` loops.

Real World Example

Defining a hidden 'id' property on an object that cannot be altered (`writable: false`) and doesn't show up when looping over the object (`enumerable: false`).

Common Use Cases

  • •Library authoring
  • •Protecting sensitive object data
  • •Getters and Setters

Interactive Example

Loading...
Console output will appear here...

Interview Questions

basic

  • How do you define a property with descriptors?

intermediate

  • What does `enumerable: false` do?

advanced

  • What is the difference between `writable: false` and `configurable: false`?

Flash Cards

Question

What does enumerable do?

Click to reveal answer
Answer

If `enumerable: false`, the property will not show up in `for...in` loops, `Object.keys()`, or JSON.stringify(). It is practically invisible during iteration, though it can still be accessed directly via `obj.prop`.

Question

Writable vs Configurable?

Click to reveal answer
Answer

If `writable: false`, the value cannot be changed. If `configurable: false`, the property cannot be deleted (`delete obj.prop` fails), AND its descriptors cannot be redefined ever again.