JavaScript Prototyping – Why console.log Shows Prototype/Constructor Pattern Indefinitely

constructorsjavascriptprototyping

I've always noticed this, but never actually understood what's happening here. I have a fairly simple object that I've put in a console.log. It has a seemingly never ending pattern of prototype -> constructor -> prototype -> etc. What exactly is it's purpose?

enter image description here

Best Answer

It doesn't have a purpose. As you can see, it only annoys you without giving out any additional information. It only has a reason.

What's happening is that the structure you're printing has a cyclical reference (the prototype knows about the contructor, and the constructor knows about its prototype), and the logger isn't smart enough to realize it will never finish if it naively follows all references.

Related Topic