I tried spread in javascript (node and chrome).
thanks to @jonrsharpe, @Quentin show me What are the rules for JavaScript's automatic semicolon insertion (ASI)? explains that semicolon is necessary and that explain why is necessary use a semicolon.
let c, d
[ c, ] = [7, 8]; // <-- semicolon is necessary
[ , d ] = [7, 8] // Otherwise, here: Uncaught SyntaxError: Unexpected token ,
let c, d
[ , d ] = [7, 8]; // <-- semicolon is necessary
[ c, ] = [7, 8] // Otherwise, here: Uncaught SyntaxError: Unexpected token ]
Just for curious, I keep tried testing without semicolon and discover this behavior:
let c, d
[ c, ] = [3, 4]
[ c, d ] = [5, 6]
console.log(c) //<-- 5
console.log(d) //<-- undefined
what explains 'd' keeps "undefined"? I hoped at least an error o d with some value.