JS Built-ins
Prototypesintermediate

Prototypes β€” Object.create with property descriptors

πŸ“– Usage Example
const obj = Object.create({}, {
  x: { value: 10, writable: false, enumerable: true, configurable: false }
});
obj.x; // 10

The second argument accepts property descriptors for fine-grained control.

Creating Objects with Defined Properties

The second argument to Object.create() allows you to define properties with descriptors. You can specify if properties are writable, enumerable, or configurable.

Challenge: Use property descriptors to create objects with read-only properties and other constraints.

πŸ’‘ Hints (3)
  • β€’ Descriptors specify value, writable, enumerable, and configurable
  • β€’ writable:false prevents assignment
  • β€’ enumerable:false hides from for...in loops