emporio emporio - 1 year ago 65
Node.js Question

NodeJS watcher printing undefined after logging function to console

I am playing around with NodeJS watchers and have written something like this in


setTimeout(() => {
var z = () => {console.log('today');}
}, 1000);

I then run
node debug debugger.js
in Git Bash which returns:

break in C:\Users\Eigenaar\OneDrive\dev\NodeJS\debugger.js:1
> 1 x = 5;
2 setTimeout(() => {
3 debugger;

I hit
couple of times to run through the debugging process. In the end I get:

< today
< undefined

Why is undefined being returned? What is undefined?

Answer Source

You're logging the result of the function z(), which equals console.log('today'). console.log is a void function and thus returns null, which is undefined as a string.