Is there an error in verifying the conclusion that JavaScript modifies the actual parameter value within the function?

first quote original

When
calls a function, the value passed to the function is called the function argument (value passing), and the function parameter at the corresponding position is called the formal parameter. If the argument is a variable that contains the original value (number, string, Boolean), even if the function changes the value of the corresponding parameter internally, the value of the argument will not change when it is returned. If the argument is an object reference, the corresponding parameter points to the same object as the argument. If the function changes the value of the corresponding parameter internally, the value of the object pointed to by the argument will also change when returned:

to verify, I wrote the following code:

var x=1,y=2; // x, y 
var i=new String("1"), j = new String("2"); // i,j 
console.log("x="+x+",y="+y);
function fnTest(a,b){
    a=a*2;
    b=b*4;
    return a+b;
}
console.log("function result="+ fnTest(x,y));
console.log("x="+x+",y="+y); 
console.log("typeof x="+typeof(x) + ",typeof y="+typeof(y));
console.log("function result="+ fnTest(i,j));
console.log("i="+i+",j="+j); 
console.log("typeof i="+typeof(i) + ",typeof j="+typeof(j));

output:

x=1,y=2
myJavaScript.js:28 typeof x=number,typeof y=number
myJavaScript.js:29 i=1,j=2
myJavaScript.js:30 typeof i=object,typeof j=object
myJavaScript.js:36 function result=10
myJavaScript.js:37 x=1,y=2
myJavaScript.js:38 typeof x=number,typeof y=number
myJavaScript.js:39 function result=10
myJavaScript.js:40 i=1,j=2
myJavaScript.js:41 typeof i=object,typeof j=object

you can see that the value of iMagnej, which stores the reference type, has not changed. Why? Is there anything wrong with the original text?

Mar.11,2021

you did not modify the reference
modify the value

var a = 1;
a = 2;

var obj = {name:"123"};
obj = {age:"321"};//

modify reference

var obj = {name:"123"};
obj.name = "321";

function fnTest(a, b) {// let a = i,b = j;
    a = a * 2;
    b = b * 4;
    return a + b;
}

you can change it to

function fnTest(a, b) {
  a.x = 1;
}
Menu