0

Let's say hypothetically that we

  1. instantiated an array object
  2. referenced that array object in another array
  3. print out the array reference
  4. change the initial array's values
let initialArray = [1,2,3,4,5]
let referenceArray = [initialArray,6]
console.log(referenceArray)
initialArray.pop()

the output at chrome browser 96 Array(2) 0: (4) [1, 2, 3, 4] 1: 6 length: 2 However at nodeJs the output is [ [ 1, 2, 3, 4, 5 ], 6 ]

Why initialArray's value got popped at the browser but not nodeJs ?

Edit:
The referenced question states that it's fixed bug ,however the 10 years old question's error still persist , so it's clearly not related to such long-gone resolved bug .
Also the behavior i listed at this question only takes place when referencing another array object

let initialArray = [1,2,3,4,5] 
console.log(initialArray)
initialArray.pop()

normally outputs [1, 2, 3, 4, 5]

yusif
  • 71
  • 4

0 Answers0