Question about where prototype assignment goes

In Use Prototype Properties to Reduce Duplicate Code

The solution is:

function Dog(name) {
  this.name = name;
}

Dog.prototype.numLegs = 4;

// Add your code above this line
let beagle = new Dog("Snoopy");

I don’t understand why the line

Dog.prototype.numLegs = 4;

doesn’t belong inside the function. Isn’t this part of making the “recipe” for a dog?

Because all dogs would have 4 legs, instead of put it in the “recipe”, which will make all instances of Dog have that property stored in their object, we put it inside the Dog prototype, which is stored in only one place, yet all instances have access to it, just like they would, if it was part of their object.
The name prop isnt identical for every Dog, so we need to store it for every Dog object.
The prototype is a special object which stores universal data for a given object, so all other objects, which instancieate of it, have access to that data, without having to duplicate it in their body.

Thanks!

Is it even allowed to put it inside the function, like this:

function Dog(name) {
  this.name = name;
  Dog.prototype.numLegs = 4;
}

We will create a method in the constructor function only which we want to duplicate in each instance. Here because we dont want to duplicate Dog.prototype.numLegs = 4; thats why we will keep it outside to avoid duplication and for memory efficiency.