1

The following valid ES6 in WebStorm:

let {a,b} = {a:0,b:0};
{a,b} = {a:2,b:4};

shows an error at the second equals sign: "expression expected". Obviously JavaScript settings are set to ES6.

By the way adding parentheses removes the error:

let {a,b} = {a:0,b:0};
({a,b} = {a:2,b:4});

Is this a bug or part of the ES6? The node compiler seems to have no problem with the first version (without the parentheses), so it doesn't seem to be part of the standard.

7
  • 1
    The first one is a syntax error, also in node. it would be let {a,b}= {a:0,b:0} or the second version. Commented Nov 7, 2017 at 13:46
  • @baao I think that it wouldn't be let, since the a and b variables will be global. Not even var. Just global variables. Commented Nov 7, 2017 at 13:49
  • why @Kinduser ? Commented Nov 7, 2017 at 13:50
  • @baao Simple test - function x() { ({a,b} = {a:2,b:4}); }. After calling this function you will be able to access these variables in global scope. If it would be const, let or even var, you wouldn't have access to it outside function. Commented Nov 7, 2017 at 13:52
  • 1
    Yeah, I'm not sure about it... Your interpretation makes more sense than mine (and his code)... :-) @Kinduser Commented Nov 7, 2017 at 13:56

2 Answers 2

3

This is not a bug, this is how ExpressionStatement are:

NOTE An ExpressionStatement cannot start with a U+007B (LEFT CURLY BRACKET) because that might make it ambiguous with a Block. An ExpressionStatement cannot start with the function or class keywords because that would make it ambiguous with a FunctionDeclaration, a GeneratorDeclaration, or a ClassDeclaration. An ExpressionStatement cannot start with async function because that would make it ambiguous with an AsyncFunctionDeclaration. An ExpressionStatement cannot start with the two token sequence let [ because that would make it ambiguous with a let LexicalDeclaration whose first LexicalBinding was an ArrayBindingPattern.

Sign up to request clarification or add additional context in comments.

Comments

0

Put parens around your assignment. For example, the following is correct

let foo
({foo = 3} = {foo: 2})

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.