I would like to evaluate
var foo = \"foo\";
console.log(foo);
as a block, instead of evaluating line by line
var foo = \"f
Node.js REPL supports blocks and is able to return the last expression from a block, so do some other console implementations (Chrome devtools console).
This may result in syntax error, this is a breaking change in Node 10.9.0. { could be a object literal, a block cannot be unambiguously evaluated as a block:
{
var foo = "foo";
console.log(foo);
}
While this can be unambiguously evaluated as a block and will return undefined:
;{
var foo = "foo";
console.log(foo);
}
Since the last expression from a block is logged, console.log isn't needed here:
;{
var foo = "foo";
foo;
}
Notice that this is block scope, so let, const and class won't leak to REPL scope, this behaviour can be desirable or not.