问题是:
longhao33@hePC:~$ node --harmony test.js
/home/longhao33/test.js:1
(function (exports, require, module, __filename, __dirname) { let str = 'es666666666666';
^^^
SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:413:25)
at Object.Module._extensions..js (module.js:452:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:475:10)
at startup (node.js:117:18)
at node.js:951:3
但在以下情况下支持“let”:(太奇怪了!)
longhao33@hePC:~$ node --harmony
> let str = 'es66666666666'
undefined
> str
'es66666666666'
test.js的内容:
让str ='es666666666666'; 的console.log(STR);
提前致谢。
答案 0 :(得分:5)
您在test.js
的顶部缺少1.23
1 //it's valid...
23.34e-10 //scientific notation
(如错误消息所示)。
它适用于REPL,因为'use strict';
is automatically included during code evaluation。