0

We've been happily omitting semicolons for a few years now in JS ES6. But today I ran across a syntax error highlighted by WebStorm (JS language version set to JSX, ESLint) when performing a destructuring assignment. The code:

const myArray = ['123', 'abc']
let a, b
[a, b] = myArray
[a, b] = myArray
console.log ([a, b])

The code runs without a problem in a console. However Webstorm/ESLint did not like the 2nd deconstructuring assignment and was only happy if line 3 was terminated with a semicolon. What is the explanation?

ianbeks
  • 2,078
  • 1
  • 22
  • 24
  • Thanks @adiga. Didn't find those questions in my research. – ianbeks Sep 09 '19 at 12:12
  • The code *works*, but it's very confusing - linters are there to (among other things) prod you to write less confusing code. – CertainPerformance Sep 09 '19 at 23:01
  • @CertainPerformance the second destructuring doesn't work. If `c, d` are declared and the second destructuring is changed to `[c, d] = myArray`, it will not work. – adiga Sep 10 '19 at 19:02
  • @adiga Oh, sure. By "the code works" I meant that it incidentally produces the desired output (due to the duplicate `[a, b]` assignment, despite the use of the comma operator), but the reason *why* it produces the desired output despite the lack of ASI is quite confusing – CertainPerformance Sep 10 '19 at 22:00

0 Answers0