Difference between instanceof and constructor property

javascript

Solution

"Is a instanceof b exactly equivalent to a.constructor === b?

No.

"If not, what's the difference between the two?"

`instanceof` also checks for "inherited" constructors.

For more information, see the spec. (here and here)

Code example:

class Parent {}
class Child extends Parent {}
const c = new Child()

c instanceof Child // true
c instanceof Parent // true (Inherited)

c.constructor === Child // true
c.constructor === Parent // false

Problem

Is `a instanceof b` exactly equivalent to `a.constructor === b`? If not, what's the difference between the two?

Original source

Related problems