Chrome/Firefox console.log始终在行后附加"undefined" [英] Chrome/Firefox console.log always appends a line saying 'undefined'

查看:143
本文介绍了Chrome/Firefox console.log始终在行后附加"undefined"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次执行console.log时,都会在输出日志后附加一行undefined的行.

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

在Windows和Linux上的Firefox和Chrome中都会发生这种情况.

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

推荐答案

如果您是从JS文件运行console.log(),则不应在此undefined行后面添加

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

如果您是从控制台本身运行console.log(),则是有道理的.这是为什么:在控制台中,您可以键入变量的名称(例如,尝试键入window),并打印有关该变量的信息.当您从控制台运行任何void函数(例如console.log)时,它还会打印出有关返回值的信息,在这种情况下为undefined.

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.

我在Chrome浏览器(Mac ver 23.0.1271.101)上测试了这两种情况,并且确实在控制台内运行undefined行时看到了undefined行.当我在控制台中编写以下行时,也会出现此undefined:var bla = "sdfdfs"

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"

这篇关于Chrome/Firefox console.log始终在行后附加"undefined"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆