Question presented to candidate: "How does the instanceof operator actually work internally, and what does it check?"
What a strong answer should cover:
- instanceof checks whether a constructor's prototype property appears anywhere in an object's prototype chain -- it walks the chain, comparing each link against Ctor.prototype, until it finds a match or reaches null.
- It is genuinely re-evaluated on every use, not cached -- reassigning a constructor's prototype after an instance already exists can change what instanceof reports for that pre-existing instance.
- Primitives never satisfy instanceof for their wrapper type (for example "str" instanceof String is false), while an explicitly boxed wrapper object does.
- instanceof is an overridable protocol, not hard-wired behavior -- a class can define a static Symbol.hasInstance method to fully customize what instanceof reports for it.
- instanceof only works reliably within a single realm (the same global environment) -- a value from a different realm (a different iframe, a different vm context) can genuinely fail an instanceof check against the "same" built-in type, which is why Array.isArray exists as a cross-realm-safe alternative for arrays specifically.
Code / implementation expected: Yes -- a runnable snippet that reimplements instanceof by hand using nothing but Object.getPrototypeOf, and confirms it matches the real operator.