I wrote a function called `protoDepth` that calculates the depth of an object's prototype chain:

```
function protoDepth(obj) {                                                                                                                                                                   
  var depth = 0                                                                                                                                                                              
    , proto                                                                                                                                                                                  
  while (proto = Object.getPrototypeOf(obj)) {                                                                                                                                               
    obj = proto                                                                                                                                                                              
    depth++                                                                                                                                                                                  
  }                                                                                                                                                                                          
  return depth                                                                                                                                                                               
}

```

Then I wrote a test for this function, which unexpectedly failed:

```
describe('`protoDepth`:', function() {                                                                                                                                                
  function A() {}                                                                                                                                                    
  function B() {}                                                                                                                                                    
  var a, b                                                                                                                                                                                 

  beforeEach(function() {                                                                                                                                                                  
    a = new A                                                                                                                                                                              
    B.prototype = a                                                                                                                                                                        
    b = new B                                                                                                                                                                              
  })                                                                                                                                                                                       

  it('provides the correct prototype depth.', function() {                                                                                                                                 
    expect(protoDepth(b)).toBe(2)                                                                                                                                                     
  })                                                                                                                                                                                       
})  

```

I expected the depth to be `2`; that is, `depth++`, I thought, would only be executed twice:

* `depth` is `0`
* The prototype of `b` is `a`; depth is `1`
* The prototype of `a` is `Object`; depth is `2`
* The prototype of `Object` is `null`; end of story.

But this is wrong. It appears that the prototype of `a` is `a`. Here's the local scope at the first line of execution:

![enter image description here](https://i.stack.imgur.com/bssJL.png)

![enter image description here](https://i.stack.imgur.com/RoLkt.png)

What's going on here? Why is A the `__proto__` of a? Since I didn't set `A.prototype`, isn't it `Object` by default?