Home >Web Front-end >JS Tutorial >Explanation of passing by value of js function parameters
function setName(obj){ obj.name='test'; obj=new Object() obj.name='test1'; }var person=new Object(); setName(person); console.log(person.name);//输出test
The parameters of the above function are passed by value. If obj is passed by reference, person is also modified.
When the reference type is passed to the parameter of the function, the value saved by person is copied to the parameter of the function, and the value points to the application of the object. Obj=new Object() in the function is equivalent to modifying the internal obj. At this time, obj no longer points to the object pointed to by person.
The above is the detailed content of Explanation of passing by value of js function parameters. For more information, please follow other related articles on the PHP Chinese website!