Skip to content

QuizNot attempted

instanceof

What does x instanceof F actually check?
1–4 to choose, Enter to submit
Show answer & explanation

Correct answer:

  • Whether F.prototype appears anywhere in x's prototype chain
  • instanceof walks x's prototype chain (Object.getPrototypeOf repeatedly) looking for the current F.prototype object (customisable via Symbol.hasInstance).
  • Not 'created by new F': reassign F.prototype and old instances fail
  • Object.create(F.prototype) passes without new.
  • Not x.constructor === F: constructor is an ordinary, overwritable property and isn't consulted.
  • Not 'F has property x': that is the in operator.