LESSON 10 / 16·2 min readIntermediate

How do prototypes and classes work?

Try code in the playground
01 Understand02 Recall03 Prepare

Understand the concept

A prototype is an object from which another object can inherit properties and methods. When a property is missing on an object, JavaScript follows its prototype chain until it finds the property or reaches null. Classes provide structured syntax for constructing objects and sharing methods through that mechanism.

Important ideas

  • If a property is missing, JavaScript looks up the prototype chain.

  • Class methods are usually shared through the prototype.

  • Composition means combining small pieces of behavior instead of extending a large parent class.

  • Instance fields belong to individual objects; ordinary class methods are shared through the prototype.

  • A child can override a parent method, but deep inheritance chains can make behavior hard to follow.

PAUSE & RECALL

Can you explain it without the notes?

How do prototypes and classes work?

Use your own words. Explain an example and one limitation before checking the explanation.

Check your explanation

A prototype is an object from which another object can inherit properties and methods. When a property is missing on an object, JavaScript follows its prototype chain until it finds the property or reaches null. Classes provide structured syntax for constructing objects and sharing methods through that mechanism.

CONNECT IT TO YOUR INTERVIEW

Turn this concept into a clear answer.

  • Explain the lookup chain first, then explain class syntax; JavaScript inheritance remains prototype-based.
Practice this concept
YOUR NEXT STEP

Keep connecting the ideas.

Next lesson: Is spread a deep copy?

Adapted from 01_JAVASCRIPT_TYPESCRIPT.md · “How do prototypes and classes work?”. Examples are study fragments; framework behavior can depend on your version.