A strange result in the output of Inherit Behaviors from a Supertype challange

Tell us what’s happening:
I pass the challenge, but when I put in the console:


I saw in the output:

nom nom nom
nom nom nom

Why there is undefined two times and where it comes from?

My code so far

function Animal() { }

Animal.prototype = {
constructor: Animal,
eat: function() {
  console.log("nom nom nom");

// Only change code below this line

let duck = Object.create(Animal.prototype); // Change this line
let beagle = Object.create(Animal.prototype); // Change this line

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.16; rv:84.0) Gecko/20100101 Firefox/84.0.

Challenge: Inherit Behaviors from a Supertype

Link to the challenge:

That’s because eat() method doesn’t return anything. The nom nom nom is written to console by the method itself, not from the fact of wrapping method call in console.log(duck.eat()).

It can be written just duck.eat(), the nom nom nom will still appear in console, but undefined will not that way.

1 Like