Search code examples
node.jscircular-reference

Node print [Circular] in console


I am studying data structures, doubly linked list, right now. I would like to see my .prev property, but it keeps just printing [Circular] is there a way to go around this?

Thanks!


Solution

  • If anyone just started studying data structures like me and went came across this problem. [Circular] simply means that it's pointing to the node that points to the other node that points to this node.

    So somthing like:

    NodeA.next = NodeB NodeB.prev = NodeA

    since the relationship is circular, meaning, they point to each other. That's why we just get [Circular] instead of the whole node printed.