Friday 21 April 2017

Why doesn't this snippet work in the node repl?

I just started playing with ES6 and Node, experimenting with the new features in a node repl:

{
  const str = 'Alice';
  let arr = [];

  for (let c of str) {
    arr.push(c);
  }

  arr;
}

Errors thrown:

const str = 'Alice';
      ^^^
SyntaxError: Unexpected identifier

  arr;
ReferenceError: arr is not defined

I couldn't figure out what I did wrong (thinking maybe the block statement doesn't work that way), so I turned to the Chrome console to confirm. The snippet works fine. So why it doesn't work in the node repl (v7.8.0)?



via damonh

No comments:

Post a Comment