2

im able to do this

[a, b] = await function1(a, b)

but when i do this

[a, b] = await function1(a, b) [a, b] = await function2(a, b)

i get this error message

SyntaxError: Invalid left-hand side in assignment expression
[a, b] = await function1(a, b)
         ^
[a, b] = await function2(a, b)

i have found a work-around but would like to know if theres a way to make my example work.

thanks in advance

lifeguru42
  • 156
  • 1
  • 12

1 Answers1

5

You just need to add semicolons in. It thinks the second set of [a, b] is part of the same expression, and more specifically that it's an array index. Ie, it sees this much:

[a, b] = await function1(a, b)[a, b] =

... and then thinks "woah, i can't assign anything to await function1(a, b)[a, b]"

So instead do:

[a, b] = await function1(a, b); // <-- added semicolon, fixing the issue
[a, b] = await function2(a, b); // <-- added semicolon for consistency
Nicholas Tower
  • 72,740
  • 7
  • 86
  • 98