对于...的:未定义的日志
For...of : undefined log
我得到了这个简单的函数,我想控制台输出数组中的值:
function findRoutes(routes) {
for (let value of routes) {
console.log(value)
} }
console.log(findRoutes([["MNL", "TAG"], ["CEB", "TAC"], ["TAG", "CEB"], ["TAC", "BOR"]]))
我的控制台是:
["MNL", "TAG"]
["CEB", "TAC"]
["TAG", "CEB"]
["TAC", "BOR"]
undefined
最后 "undefined" 是什么?
对于Javascript,
We know the functions returned value could be an object
, an array
, a
function
, a boolean
, string
and so on. But If the function has
no return
statement, undefined
is returned. 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.
在此处阅读前 2 个投票答案 Chrome/Firefox console.log always appends a line saying undefined 以清楚地理解为什么您会在数组后看到最后一个 undefined
?。几个月前我对最后一个 undefined 也有同样的困惑。
我得到了这个简单的函数,我想控制台输出数组中的值:
function findRoutes(routes) {
for (let value of routes) {
console.log(value)
} }
console.log(findRoutes([["MNL", "TAG"], ["CEB", "TAC"], ["TAG", "CEB"], ["TAC", "BOR"]]))
我的控制台是:
["MNL", "TAG"]
["CEB", "TAC"]
["TAG", "CEB"]
["TAC", "BOR"]
undefined
最后 "undefined" 是什么?
对于Javascript,
We know the functions returned value could be an
object
, anarray
, afunction
, aboolean
,string
and so on. But If the function has noreturn
statement,undefined
is returned. 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.
在此处阅读前 2 个投票答案 Chrome/Firefox console.log always appends a line saying undefined 以清楚地理解为什么您会在数组后看到最后一个 undefined
?。几个月前我对最后一个 undefined 也有同样的困惑。