0

can someone help me to understand what is wrong on this:

var foo = {
  bar: 1,
  baz: 2
};

var { bar, baz } = foo;

I got error SyntaxError: Unexpected token {. I'm using node v5.4.1 So I'm not sure if problem is in node or in syntax. For example let works well. Many thanks

John
  • 2,494
  • 5
  • 21
  • 24

1 Answers1

0

Node does not yet support all ES6 specifications. Destructuring is not supported as mentioned here https://kangax.github.io/compat-table/es6/

You need to pass by a transpiler like Babel to be able to use it.

  • Thanks for answer, I'm using babel, but nothing changed: `require("babel-core").transform("code", {"presets": ["es2015"]});` – John Feb 02 '16 at 14:28