Hello forum!
I have encountered some behaviour that I can seem to understand. Please see code below:
function someFunction(arr) {
const someArr = arr;
someArr.push(1, 2, 3);
console.log(arr);
//logs [arr, 1, 2, 3] but why?
console.log(someArr);
//also logs [arr, 1, 2, 3] as expected.
}
My question is a follows:
Why does changing contents of the array someArr also changes the contents of the array arr ?
I have tried searching the forum and the web, but couldn’t find much (or couldn’t formulate my search query properly).
Any explanations or hints of where (or how) to look for an explanation are highly apreciated.
Thanks and stay heathly.