Node shell 常常也叫做 Node REPL——REPL代表Read-Eval-Print-Loop。
启动:在 shell 中输入 node 就可以了
client:node marcw$ node
>
下面输入了一些代码:
> console.log("Hello World");
Hello World!
undefined
>
输出的第一行是执行的代码的结果。这里,你用 Node 的全局变量 console 和它的 log 函数打印出 Hello World!
输出的最后总是之前代码的 resulting value。每一个语句、函数调用或表达式都带有一个值,该值会被打印在 Node shell 中。If there is no evaluated expression value 或 被调用的函数没有返回任何值,此时就会返回 undefined。
要退出 REPL,按 Ctrl+D(Windows也一样)。
Node REPL 中的 ... 意味着它期望你输入一些什么,这样它才能完成当前的表达式、语句或函数。如果你不是很理解为什么它给你省略号?你只要输入 .break(注意前面有的点) 就可以摆脱它了。