Search code examples
javascriptvisual-studio-codecircular-reference

What does [Circular *1] mean (VS Code)


Console.log of an object with a circular reference in vscode displays includes following snippet: "[Symbol(network)]: [Circular *1]". I get why its circular, and I imagine the exact format is specific to VS Code but either way I would like to know more info - like what "*1" means.

Really surprised nothing comes up when I google '[Circular *1]'. What's the deal?


Solution

  • It is a number indicating which object it is referencing:

    const { inspect } = require('util');
    
    const obj = {};
    obj.a = [obj];
    obj.b = {};
    obj.b.inner = obj.b;
    obj.b.obj = obj;
    
    console.log(inspect(obj));
    // <ref *1> {
    //   a: [ [Circular *1] ],
    //   b: <ref *2> { inner: [Circular *2], obj: [Circular *1] }
    // }
    

    Check out how each object have a <ref *n> which reflect on [Circular *n].