亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

輸出中的“未定義”是什么意思?

輸出中的“未定義”是什么意思?

一只名叫tom的貓 2021-05-14 15:15:30
在節點解釋器中:> 1+34> var name=12undefined> console.log(typeof name)numberundefined是什么undefined在輸出是什么意思?為什么不1 + 3輸出undefined,而其他兩個卻不輸出呢?
查看完整描述

2 回答

?
qq_花開花謝_0

TA貢獻1835條經驗 獲得超7個贊

因為1 + 3回報4。變量聲明不返回任何內容,也不返回任何內容console.log。您看到的值undefined是返回值。但是,變量分配(var hello; hello = "hello")確實返回分配的值(感謝VLAZ指出)。


查看完整回答
反對 回復 2021-05-27
?
翻過高山走不出你

TA貢獻1875條經驗 獲得超3個贊

您正在使用節點REPL(moreinfo)


REPL代表Read-Eval-Print-Loop。顧名思義,它將讀取您輸入的內容,對其進行評估(運行),將結果打印并重復。打印部分將打印您返回的任何代碼。所以它正在做的事情是這樣的:


console.log(eval({your expression here}))

因此,適用于您的案例,我們有:


console.log(1+3) // 4

console.log(var name=12) // undefined because an attribution doesn't return anything

console.log(console.log(typeof name)) // first the inner console.log will print the type of name (number) and then the outer console.log will print undefied (the return of the inner console.log).

希望這樣更清晰。


查看完整回答
反對 回復 2021-05-27
  • 2 回答
  • 0 關注
  • 217 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號