Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Is it possible? It doesn't seem to work in my REPL, neither with nor without --harmony.

What I'd really like to do is use for..of loops, but let seems a simpler thing to troubleshoot and is likely the same reason.

Anyone know anything about the status of these?

like image 760
user2958725 Avatar asked Jan 12 '23 22:01

user2958725


1 Answers

$ node --version
v0.10.13

It was a bit cryptic, you'd think just --harmony would work, but you need to add in a use strict somewhere (which you can do at 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
> 

Much happy!

However, I tried a simple of comprehension and it didn't work:

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

With no luck. It looks like you may have to go past the current stable release to get all the harmony features.

like image 104
jcollum Avatar answered Jan 23 '23 15:01

jcollum