Js function problem

 var ary=[1,2,3,4];
    function fn(ary){
        ary[0]=0;
        ary=[0];
        ary[0]=100;
        return ary;
    }
    var res=fn(ary);//res
    console.log(ary);
    console.log(res);
Mar.14,2021

var ary=[1,2,3,4];
    function fn(ary){
        ary[0]=0;//
        ary=[0];//
        ary[0]=100;//
        return ary;
    }
    var res=fn(ary);//res
    console.log(ary);//
    console.log(res);

The

function is also an object, which is a reference data type, and when assigned, it passes a reference value, which is equivalent to an address.

 var res=fn;//res 
  
  // 
  var res = fn(ary)//  fn(ary)  res
  // res  return  ary
Menu