[英]What does the `undefined` mean in node.js console?
I wrote some code in the Node.js console, and noticed sometimes it return an undefined
. 我在Node.js控制台中编写了一些代码,并注意到有时它返回
undefined
。
See the following code. 请参阅以下代码。
Some lines return undefined
but some don't. 有些行返回
undefined
但有些则没有。
What does the undefined
mean? undefined
是什么意思?
PS D:\test\hello> node
> "two\nlines"
'two\nlines'
> var s = "hello, world"
undefined
> s.charAt(0)
'h'
> s.charAt(s.length -1)
'd'
> var anyString = 'Mozilla';
undefined
> console.log(anyString.substring(3, 0));
Moz
undefined
But what does the last line , it returns undefined but also returns Moz?
但是最后一行返回undefined但还返回Moz是什么呢?
> console.log(anyString.substring(3, 0)); Moz undefined
console.log
explicitly outputs to the console, which is the Moz
you're seeing. console.log
显式输出到控制台,即您所看到的Moz
。 It then returns a value (or well, it doesn't), which is the value undefined
, which is logged to the console because you're in the interactive environment and that's what it does. 然后,它返回一个值(或者不是),该值是
undefined
,由于您处于交互式环境中,因此将其记录到控制台中。
The point of using the interactive command line is to be able to try operations and see their result instantly, without complex alert
or debugging setups. 使用交互式命令行的目的是能够尝试操作并立即查看其结果,而无需复杂的
alert
或调试设置。 You type a command, you see its result. 您键入命令,您将看到其结果。 Sometimes that result is the value
undefined
, sometimes it's another value. 有时结果是
undefined
,有时是另一个值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.