I obtained the following trace from Chrome developer tool’s console:
> a = [1]
[1]
> b = [2, a]
[2, Array[1]]
> a.push(b)
2
> a.toString()
"1,2,"
It seems the toString() intelligently skipped the recursive part of the object graph. Is this a standard behavior documented somewhere?
All of this basically means that the result is a call to
Array.prototype.join(), which is defined in15.4.4.5and doesn’t mandate any recursion detection:So, is it a standard-guaranteed behaviour? No.