2 回答

TA貢獻1835條經驗 獲得超7個贊
因為1 + 3
回報4
。變量聲明不返回任何內容,也不返回任何內容console.log
。您看到的值undefined
是返回值。但是,變量分配(var hello; hello = "hello"
)確實返回分配的值(感謝VLAZ指出)。

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).
希望這樣更清晰。
添加回答
舉報