Skip to content

Chapter 10 of 33

Objects and Prototypes

Model properties, methods, descriptors, prototypes, copying, and object integrity.

42 minutes 10 quick checksBy Subha Prasad
Lesson 10 of 33Course navigation

Lesson content

Read, practise, then check your understanding

Objects map string or symbol keys to property descriptors. Dot notation suits fixed identifiers; bracket notation accepts computed keys.

Behavior and inheritance

const accountPrototype = {
  deposit(amount) { this.balance += amount; }
};

const account = Object.create(accountPrototype);
Object.assign(account, { owner: "Mira", balance: 100 });
account.deposit(50);

Lookup follows the prototype chain. Use Object.hasOwn when inherited properties must not count. Spread and Object.assign make shallow copies and do not preserve all descriptors or prototypes. Getters/setters expose computed access but can hide work. freeze prevents top-level mutation, not deep mutation. Prefer data with clear ownership and avoid modifying built-in prototypes.

Knowledge check

Answer every question correctly to complete this chapter.

Which statement best describes object?
Which JavaScript term matches this description: A mutable collection of keyed properties with a prototype.
Which statement best describes property descriptor?
Which JavaScript term matches this description: Metadata controlling a property's value/getter, writability, enumeration, and configurability.
Which statement best describes prototype?
Which JavaScript term matches this description: The object consulted when an own property lookup fails.
Which statement best describes method?
Which JavaScript term matches this description: A function-valued property invoked with a receiver.
Which statement best describes Object.create?
Which JavaScript term matches this description: An operation creating an object with an explicitly selected prototype.

0 of 10 checks passed

Your progress is saved on this device.

Objects and Prototypes | JavaScript Lesson | Subha Prasad