How to write multiple lines of code in Node REPL

后端 未结 5 2162
一个人的身影
一个人的身影 2020-12-23 19:35

I would like to evaluate

var foo = \"foo\";
console.log(foo);

as a block, instead of evaluating line by line

var foo = \"f         


        
5条回答
  •  南笙
    南笙 (楼主)
    2020-12-23 19:56

    You can use if(1){ to start a block that will not finish until you enter }. It will print the value of the last line of the block.

    > {
    ... var foo = "foo";
    ... console.log(foo);
    ... }
    foo
    undefined
    

    In multiline mode you miss out on a lot of REPL niceties such as autocompletion and immediate notification of syntax errors. If you get stuck in multiline mode due to some syntax error within the block, use ^C to return to the normal prompt.

提交回复
热议问题