emporio emporio - 2 months ago 12
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

debugger.js
:

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


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
c
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

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.

Comments