Problem
let x = 5
let y = 10
[x, y] = [y, x]
Solution

If you run this code you get a “ReferenceError: y is not defined” error. This is because the JavaScript engine does not automatically insert a semicolon after 10 because the subsequent line can be parsed as a continuation of the expression. Meaning, JavaScript interprets the code like this:

let x = 5;
let y = 10[x, y] = [y, x];

To fix the issue, we can update our code to use semicolons or wrap the expression in parentheses:

let x = 5;
let y = 10;
([x, y] = [y, x]);

It’s comforting to know Douglas Crockford is (probably) out there still shaking his fist at this “insanely stupid code”.