Prototypes — How Inheritance Actually Works — Concept Check
Questions on Prototypes — How Inheritance Actually Works. JavaScript objects delegate to other objects through a prototype chain. Classes are syntax over this mechanism, not a separate system — which is why understanding the chain explains behaviour classes cannot.
Questions in this quiz
8 questions on Prototypes — How Inheritance Actually Works — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.A developer notices that calling `dog.toString()` on a custom `dog` object returns a string, even though `toString` was never defined in their code. What explains this behavior?
- A`toString` is a default method of the `dog` object.
- B`toString` is inherited from `Object.prototype`.
- C`toString` is automatically added to all objects.
- DThe `class` keyword adds `toString` to all instances.
2.In a debugging session, you see `Object.hasOwn(dog, 'barks')` returns `true`, but `Object.hasOwn(dog, 'breathes')` returns `false`. What does this indicate?
- A`barks` is an own property of `dog`, `breathes` is inherited.
- B`barks` is inherited from `animal`, `breathes` is an own property.
- C`breathes` is not a property of `dog` or its prototype.
- DBoth `barks` and `breathes` are own properties of `dog`.
3.A programmer creates a class `Dog` extending `Animal` and notices that `speak` is not an own property of any `Dog` instance. Why?
- AThe class syntax hides methods from instances.
- BMethods are copied to each instance at runtime.
- CInheritance prevents methods from being own properties.
- DMethods are stored on the prototype, not each instance.
4.When you create an object using `Object.create(animal)`, what is the relationship between the new object and `animal`?
- AThe new object has no connection to `animal`.
- BThe new object and `animal` are the same instance.
- CThe new object copies all properties from `animal`.
- DThe new object delegates property lookups to `animal`.
5.A developer mistakenly believes that using `class` in JavaScript creates a separate inheritance system from prototypes. What is the truth?
- A`class` is syntax sugar over the prototype system.
- B`class` prevents prototype-based inheritance.
- C`class` uses a different mechanism for inheritance.
- D`class` creates a new inheritance model.
6.What happens if you try to access a private field like `#balance` outside of its class?
- AA `ReferenceError` is thrown.
- BThe field is accessed normally.
- CA `SyntaxError` is thrown.
- DThe field is undefined.
7.In the prototype chain, where does JavaScript look for a property if it is not found on the object itself?
- AIt throws an error if not found.
- BIt follows the hidden `[[Prototype]]` link.
- CIt stops searching immediately.
- DIt copies the property from `Object.prototype`.
8.Why might `Object.getPrototypeOf(d) === Dog.prototype` return `true` for an instance `d` of class `Dog`?
- A`d` has its own copy of `Dog.prototype`.
- B`d` is linked to `Dog.prototype` by the class syntax.
- C`d` does not have a prototype.
- D`d` and `Dog.prototype` are the same object.