1. instanceof checks the chain
instanceof is true because Array.prototype appears in arr's prototype chain.
arr instanceof Array // true — Array.prototype is in arr's chainTyporithm · medium
Step 1 of 8 · intro card
Prototypes & Classes
obj instanceof Ctor is true when Ctor.prototype appears anywhere in obj's prototype chain. Object.create(proto) makes a new object whose [[Prototype]] is proto, and Object.getPrototypeOf reads that link back. instanceof simply walks the chain looking for a match.
The instanceof operator answers a prototype-chain question: obj instanceof Ctor is true exactly when Ctor.prototype is found somewhere in obj's chain. That is why arr instanceof Array and arr instanceof Object are both true — both prototypes are on the chain.
Object.create(proto) builds a brand-new object whose internal [[Prototype]] is set directly to proto, with no constructor involved. It is the most explicit way to choose an object's prototype, and Object.getPrototypeOf(obj) reads that exact link back.
Because instanceof only checks whether a constructor's .prototype is in the chain, an object created with Object.create still counts as an instanceof Object as long as Object.prototype is reachable up the chain.
instanceof is true when Ctor.prototype is in obj's chain.
Object.create(proto) makes proto the new object's [[Prototype]].
Object.getPrototypeOf reads that link back.
const arr = [1, 2, 3]
arr instanceof Array // true — Array.prototype is in arr's chain
arr instanceof Object // true — Object.prototype is further up
const proto = { greet() { return "hi" } }
const obj = Object.create(proto)
Object.getPrototypeOf(obj) === proto // true
obj instanceof Object // trueConnect each part of the code to the concept before you type.
instanceof is true because Array.prototype appears in arr's prototype chain.
arr instanceof Array // true — Array.prototype is in arr's chainObject.prototype sits higher in the chain, so arr is also an instance of Object.
arr instanceof Object // true — Object.prototype is further upObject.create(proto) makes a new object whose [[Prototype]] is exactly proto.
const obj = Object.create(proto)Object.getPrototypeOf confirms obj's [[Prototype]] is the proto we passed in.
Object.getPrototypeOf(obj) === proto // trueproto itself inherits from Object.prototype, so obj is an instance of Object.
obj instanceof Object // trueRead the concept map and follow the code breakdown.
Type the implementation, repair mistakes and work through every recall exercise.
Use the final check without hints; revisit weak concepts in short practice sessions.