DEV Community

loading...

Discussion on: Demystifying Array.prototype.flat

Collapse
zakhenry profile image
Zak Henry

There's now a new way to create a stack overflow! 🎉

a = [1,2,3]

b = [4,5,6]

a.push(b)

b.push(a)

a.flat(Infinity) 

// VM185:9 Uncaught RangeError: Maximum call stack size exceeded
//    at Array.flat (<anonymous>)
//    at <anonymous>:9:3

Collapse
laurieontech profile image
Laurie Author

I'm not even sure how you triggered that! I tried the same and ended up with a Circular reference warning and then

[1] 5163 segmentation fault node

when node crashed haha.

Well done!

Collapse
zakhenry profile image
Zak Henry

Oh interesting, I just tried this in the Chrome console, thanks for the inspiration :)