DEV Community

Cover image for JavaScript Quiz Question #4: Prototypal Inheritance
Nick Scialli (he/him)
Nick Scialli (he/him)

Posted on

JavaScript Quiz Question #4: Prototypal Inheritance

In this question, we have a Dog constructor function. Our dog obviously knows the speak command. What gets logged in the following example when we ask Pogo to speak?

function Dog(name) {
  this.name = name;
  this.speak = function() {
    return 'woof';
  };
}

const dog = new Dog('Pogo');

Dog.prototype.speak = function() {
  return 'arf';
};

console.log(dog.speak());
Enter fullscreen mode Exit fullscreen mode

A) woof
B) arf

Put your answer in the comments!

Top comments (5)

Collapse
 
wierdorohit123 profile image
rohit raut

Woof

Collapse
 
ccelsio profile image
Célsio Capapelo

woof

Collapse
 
pris_stratton profile image
pris stratton • Edited

It should be “woof” because dog.speak will get called and dog.proto.speak will never be searched for.

Collapse
 
whomahtab profile image
Mahtab

Error

Collapse
 
sagarchawla076 profile image
Sagarchawla076

woof