Changing array in JavaScript function changes array outside of function?

后端 未结 2 1260
清歌不尽
清歌不尽 2020-12-17 03:14

Why the two scripts behave differently? I want the to use the first script, but in the second drawData() call it changes data; it\'s weird and not

2条回答
  •  鱼传尺愫
    2020-12-17 03:30

    First variant modifies object passed as parameter to function (which happens to be array) - so this change is seen outside function. Second variant assigns new value to function parameter (which happens to be reference to array) but does not change array itself.

提交回复
热议问题