javascriptnode.jsvisual-studio-codevscode-debugger

Why are there 2 [[Prototype]]s in an JS Array in VS Code's Debug Console?


I've run the following code using Node.js in VS Code

const theArray = [1,2,3];
const theObject = {'a': 1};
console.log(theArray);
console.log(theObject);
debugger; // Breakpoint

Output of Code above

My problem is that there are 2 [[Prototype]] inside theArray at the same layer. I understand that there can be a [[Prototype]] inside another but not how there can be 2 directly under theArray on the same layer. This doesn't make sense to me.

(Also the [[Prototype]] = Array(0) has 2 [[Prototype]] = Object inside it.)


Solution

  • This is apparently the expected behaviour. This is how the builtin debug support for JS debugging in VS Code works for prototype chains in the debug console. When you log an object, the prototype chain will be shown at the bottom (flattened in addition to being visible when you expand each prototype up the chain, which is somewhat confusing).

    Examples of this in test harnesses for vscode-js-debug (the builtin extension providing that debug support) include: