Search code examples
javascriptnode.jsecmascript-6ecmascript-harmony

Harmony destructuring ReferenceError: Invalid left-hand side in assignment


This a weird behaviour, i've tested on Chrome and works just fine without any flag, but in node it doesn't work event with the latest version

$ node --harmony_destructuring app.js

[length, offset] = this.getint(data, offset, 2)
^    
ReferenceError: Invalid left-hand side in assignment

$ node -v

v5.11.0

Any clues on why it doesn't work or a version of node in witch works?

Thanks


Solution

  • The correct syntax would be

    const iterable = ['a', 'b'];
    const [x, y] = iterable;
    

    You can read more on destructuring here.