Skip to content
Advertisement

Why does it print “undefined” on the console? [closed]

I have the following JavaScript code:

please help

JavaScript

I expect that it should print this output:

JavaScript

But instead, it prints the following:

JavaScript

Why does it print “undefined” after each function within the method?

Advertisement

Answer

I suppose you’re calling console.log(kim.message()); and console.log(kim.interest());

console.log prints the return value of the passed function but because both the function don’t have a return statement console.log prints undefined that’s way you see those additional undefined logs.

Advertisement