Here is my confusion with return statements in Javascript:
I have a challenge on FreeCodeCamp.org to write a function that takes in 2 array's, and a position. I have to return array1 copied into array2 starting at the given position.
this code works:
function insertArrayAtPostion(arr1, arr2, postion) {
arr2.splice(n,0,...arr1);
return arr2;
}
However, I wonder why I can't just do this:
function insertArrayAtPostion(arr1, arr2, postion) {
return arr2.splice(n,0,...arr1);
}
Because I've been told JavaScript evaluates everything to the right before returning