如果console.log(4)在Chrome控制台中未定义输出,意味着什么? [英] What does it mean if console.log(4) outputs undefined in Chrome Console?
问题描述
我使用Chrome控制台写了一个简单的语句:
console.log(4)
并收到
输出:
4
undefined
undefined语句是什么意思?
未定义的语句是否意味着正确的执行?如果我通过单独的html文件执行语句,然后看看控制台,输出只是4。
解决方案 code> undefined
是 console.log(...)
的返回值。
你可以在控制台中定义两个函数,一个返回值,另一个返回值,例如像这样:
function f1(){
return 1;
}
function f2(){
return;
}
然后单独调用(手动)
f1(); // shows'1'
和
f2(); //显示'undefined'
还要注意这些返回值字符串之前的小符号。
I used the Chrome Console to write a simple statement:
console.log(4)
and received the
Output:
4
undefined
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.
解决方案 The undefined
is the return value of console.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'
and
f2(); // shows 'undefined'
Also note the little symbol before these return value string.
这篇关于如果console.log(4)在Chrome控制台中未定义输出,意味着什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!