Why this code references different result

后端 未结 4 1367
眼角桃花
眼角桃花 2020-12-11 23:21

I am new to JS and was learning value and reference types in JS but I faced some confusion on the below code:

4条回答
  •  感动是毒
    2020-12-11 23:42

    The reference to obj.arr is replaced. z = [{ x: 25 }]; simply creates a new array with a new object, { x: 25 }, inside it. Then, it places a reference to this new array into z.

提交回复
热议问题