这是jsfiddle
完整代码:
function foo1(){
return {msg: "hello1"};
}
function foo2(){
return
{msg: "hello2"};
}
// output = "foo1 = {"msg":"hello1"}"
console.log('foo1 = ' , JSON.stringify(foo1()));
//output = " foo2 = undefined "
console.log('foo2 = ' , JSON.stringify(foo2()));
Run Code Online (Sandbox Code Playgroud)
两者之间的区别在于,在foo2中,{msg: 'hello'}它位于自己的新行中.我期待解析器忽略空格?
我正在尝试在nodejs REPL的全局范围内执行类似的操作。根据我的理解,以下两个陈述均有效。查看文件
let x = await Promise.resolve(2);
let y = await 2;
Run Code Online (Sandbox Code Playgroud)
但是,这两个语句都引发错误。
有人可以解释为什么吗?我的节点版本是v8.9.4