如果在 Chrome 控制台中 console.log(4) 输出 undefined 是什么意思? [英] What does it mean if console.log(4) outputs undefined in Chrome Console?

查看:110
本文介绍了如果在 Chrome 控制台中 console.log(4) 输出 undefined 是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用 Chrome Console 写了一个简单的语句:

I used the Chrome Console to write a simple statement:

console.log(4)

并收到了输出:

4

未定义

undefined 语句是什么意思?undefined 语句是否意味着正确执行?如果我通过单独的 html 文件执行语句,然后查看控制台,输出只有 4.

What does the undefined statement mean? Does the undefined statement imply correct execution? If I execute the statement via a separate html file and then look at the console, the output is just 4.

推荐答案

undefinedconsole.log(...) 的返回值.

您可以通过在控制台中定义两个函数来看到这一点,一个返回某些内容,另一个不返回任何内容,例如像这样:

You can see this by defining two functions in the console, one returning something, and the other returning nothing, e.g. like this:

function f1() {
  return 1;
}
function f2() {
  return;
}

然后分别(手动)调用它们

And then calling them separately (manually)

f1(); // shows '1'

f2(); // shows 'undefined'

还要注意这些返回值字符串前的小符号.

Also note the little symbol before these return value string.

这篇关于如果在 Chrome 控制台中 console.log(4) 输出 undefined 是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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