Can anyone else use let statements in their Node.js REPL?

Is it possible? This does not seem to work in my REPL, with or without --harmony.

What I really would like to do is use it for ... loops, but let it seem like a simpler task to troubleshoot and probably for the same reason.

Does anyone know anything about the status of these?

+4
source share
2 answers
$ node --version
v0.10.13

It was a little cryptic, you would think it would only --harmonywork, but you need to add somewhere use strict(which you can do on the command line):

$ node --harmony --use-strict
> var letTest = function () {
...   let x = 31;
...   if (true) {
.....     let x = 71;  // different variable
.....     console.log(x);  // 71
.....   }
...   console.log(x);  // 31
... }
undefined
> letTest()
71
31
undefined
> 

Very glad!

of, :

[ square(x) for (x of [1,2,3,4,5]) ]

. , , , , .

+8

, node.js :

SyntaxError: Illegal let declaration outside extended mode

? , "use strict" . :

, ES5 " ", JS. " ". ES6 " ", .

node v11.7 , for of. I:

function* fibonacci() {
    let prev = 0, curr = 1, temp;
    for (;;) {
        temp = prev;
        prev = curr;
        curr = temp + curr;
        yield curr;
    }
}

for (let n of fibonacci()) {
    if (n > 1000)
        break;
    console.log(n);
}

for of , .

+1

All Articles