var a = 1
var b = 3
console.log(a, b)
[a, b] = [b, a]
console.log(a, b)
above code will trigger an error:
[a, b] = [b, a]
^
TypeError: Cannot set property '3' of undefined
putting a semi colon in console.log line solves it:
````
var a = 1
var b = 3
console.log(a, b);
[a, b] = [b, a]
console.log(a, b)
````
is this a bug? thanks
This is just how javascript works (with automatic semicolon insertion), so it's not a bug.
Also, this StackOverflow answer is a (IMO) pretty clear explanation of what's going on: https://stackoverflow.com/a/39748189/436641
@sqllyw U can take a look at this
11.9 Automatic Semicolon Insertion
@sqllyw Your code is actually parsed as:
console.log(a, b)[a, b]
ie
console.log(a, b)[3]
ie
undefined[3]
so this produces the mentioned error message.