Why does this JavaScript code print “undefined” on the console?

It’s because the “printCounter()” function itself returns undefined. That’s the console telling you the result of the expression.

Change “printCounter()” by adding return "Hello Anton!"; to the end 🙂

It’s a little confusing to say it “returns undefined“; really, it has no explicit return, but it’s the same effect.

Leave a Comment