Trap of Javascript
1. Reference before assignment
function ShuffleArray(array){ // inplace
for (let i=array.length-1; i>0;i--){
var j = Math.floor(Math.random()*(i+1));
[arr[i], arr[j]] = [arr[j], arr[i]]; // no error
}
}
This function not only cannot modify the array, but also affects the global variables!
2. Pass by reference (2d array)
arr1 = [[0,0], [1,1]];
arr2 = arr1;
console.log(arr1);
// output: [[3,0], [1,1]] ???
// console.log(...arr1) instead
arr2[0][0] = 3;
console.log(arr2);
// output: [[3,0], [1,1]]
The output will be changed even before the assignment.