Today, the class threw out a piece of code about deconstruction:

  let a = 1
  let b = 2
  [a, b] = [b, a]
  console.log(a, b)
Copy the code

The result is not correct:

The code didn’t seem to have any problems, so there was a lot of discussion, a lot of practice, and we came to the conclusion that we didn’t add a semicolon. Add the semicolon:

  let a = 1;
  let b = 2;
  [a, b] = [b, a];
  console.log(a, b)
Copy the code

Run, get:

The end. But it’s worth noting.

“A semicolon is ok when a line begins with a parenthesis or square parenthesis, but not at all.” Learn from the big guy, think more summary.

“Big” especially on zhihu answer link: www.zhihu.com/question/20…