📌  相关文章
📜  为什么检查工具显示额外的未定义 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:55.458000             🧑  作者: Mango

代码示例1
102

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"