const test = () => {
const arr = [1, 2]
console.log("any strings") // focus on this line
[arr[0], arr[1]] = [arr[1], arr[0]]
}
const test1 = () => {
const arr = [1, 2]
console.log("any strings"); // add a semicolon will works or comment this line will works too
[arr[0], arr[1]] = [arr[1], arr[0]]
}
test() // error
test1() // works
Why does the first function test throw error "Cannot set property '2' of undefined"?
(,[,/,+,-or`.