Home  >  Article  >  Web Front-end  >  Explanation of passing by value of js function parameters

Explanation of passing by value of js function parameters

一个新手
一个新手Original
2017-09-26 09:36:551550browse


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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn