About printing undefined

hi, I am following the steps in the following lesson:
https://www.codecademy.com/content-items/7e182ef11df387e8b51708a52df36515/exercises/node-repl
After I defined global.cat and console.log it, it not only print ‘meow’ but also undefined. why? I thought it would be only ‘meow’

1 Like

TL;DR: global.cat was logged to the console, then undefined was returned by the console.log() function call.


Basically, console.log() is a function and functions always return something. If no return value is defined, then undefined is returned.

The function’s sole purpose is to log the provided parameter to the console and as such, it does not have a return value. All it does is log the parameter to the console, then return undefined.

we are not talking about python.

Hi, @xiaobai663 this is because console. log() does not return a value (i.e. returns undefined). The result of whatever you entered to the console is first printed to the console, then a bit later the message from console. log reaches the console and is printed as well. If, it is on node.js, that should help.