This code is giving “undefined” right after its successful logging…I couldn’t understand the reason for this “undefined” on last line.
function Bird(name) {
this.name = name;
}
Bird.prototype = {
numLegs: 2,
eat: function() {
console.log("nom nom nom");
},
describe: function() {
console.log("My name is " + this.name);
}
};
let p = new Bird("cde");
console.log(p.eat());
// nom nom nom
// undefined
I could not understand. Why that last line is only executed with this code. Where is that line located. Why I came across this type of “undefined” very rarely. I tried it in fcc console as well as google console. What type of other environment is available ?
an environment like the browser console prints the value of the last line of the code snippet
in this case the last line is a console.log, the output of console.log is undefined
printing to the console is a side effect for console.log, not the output