0

What exactly is happening here at the line( param = [1]) when passing the data, that the output is 0? If I switch the lines inside the function I get [0,2].

const  data = [0];

function changeData(param) {
  param = [1]
  param.push(2);

}
changeData(data);
Azm
  • 81
  • 1
  • 2
  • 8
  • 1
    *"What exactly is happening here at the line( param = [1])"* - The local variable `param` is being re-assigned to an entirely new value (a reference to the array `[1]`), replacing its previous value (a reference to the array `[0]`). – David Apr 12 '23 at 18:03
  • 1
    The equals assignment discards whatever param was and sets it to the new array. – James Apr 12 '23 at 18:08

0 Answers0