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

前端 未结 7 1795
时光说笑
时光说笑 2020-11-21 13:40

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

7条回答
  •  没有蜡笔的小新
    2020-11-21 14:13

    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"

提交回复
热议问题