Your product could be here, in front of thousands of JavaScript developers. Sponsor this spot →
JavaScript Quiz

Do objects see prototype changes made after they're created?

Do you know what will be the output of this code?

JavaScript
function Dog() {}
Dog.prototype.bark = () => "woof";

const d = new Dog();
Dog.prototype.bark = () => "WOOF";
console.log(d.bark());
Show answer and explanation

The answer is "WOOF".

d doesn’t have its own bark. Each call looks it up on Dog.prototype, which by then holds the new function.

Take the full quiz Next question →

More Classes & Prototypes questions

  1. Why does this become undefined when you extract a method?
  2. What happens when a constructor returns an object?
  3. Are JavaScript classes hoisted?
  4. Can you call a static method on a class instance?
  5. What is the difference between in and hasOwnProperty?

Related topics