Why does array.push() seem to push infinite times?

Viewed 628

Consider the following javascript code,

>> a = [1, 2]
  Array [ 1, 2 ]

>> a.push(a) 
  Array [ 1, 2, Array[3] ] 

On expanding the array, a, we get an array with infinite depth. (as viewed on the firefox developer console)

Array[3]
| 0: 1
| 1: 2
  2: Array[3]
  | 0: 1
  | 1: 2
  | 2: Array[3]
    | 0: 1
    | 1: 2
    | 2: Array[3]
    ....

[1] Why is a getting appended more than once?
[2] At what depth does it stop?

5 Answers
Related