我只是在玩 Node ,我注意到即使我为函数 Node 指定返回值仍然返回未定义。
这里出了什么问题?阅读与我的问题相关的上一篇文章,我的印象是,如果您指定返回类型 Node 不应显示未定义
最佳答案
它不会返回 undefined
,它显然返回 5
。函数声明返回 undefined
(主要是因为 (a) eval()
如何工作和 (b) because functions with no return values technically return undefined
per the standard ),但是当您调用函数本身时,例如x()
,你会得到 5
.
您会注意到全局范围内的变量声明,例如 var test = 1
,也会立即返回 undefined
在控制台中。这并不意味着test
现在是undefined
.
关于javascript - 即使函数有返回值,Nodejs也会在控制台上显示未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25778711/