Chrome/Firefox console.log always appends a line saying 'undefined'

N. Chamaa picture N. Chamaa · Jan 31, 2013 · Viewed 41.7k times · Source

Every time console.log is executed, a line saying undefined is appended to the output log.

It happens in both Firefox and Chrome on Windows and Linux.

Answer

talkol picture talkol · Jan 31, 2013

If you're running console.log() from a JS file, this undefined line should not be appended.

If you're running console.log() from the console itself, it makes sense. This is why: In the console you can type a name of a variable (for example try typing window) and it prints info about it. When you run any void function (like console.log) from the console, it also prints out info about the return value, undefined in this case.

I tested both cases on my Chrome (Mac ver 23.0.1271.101) and indeed I see the undefined line when I run it inside the console. This undefined also appears when I write this line in the console: var bla = "sdfdfs"