obj instanceof Foo kiểm tra: Foo.prototype có nằm trong prototype chain của obj không.
javascript
[] instanceof Array; // true
[] instanceof Object; // true (Array.prototype.__proto__ === Object.prototype)
({}) instanceof Array; // false — cần ngoặc, không thì {} đầu dòng bị hiểu là block
// Chain traversal:
class Animal {}
class Dog extends Animal {}
const d = new Dog();
d instanceof Dog; // true
d instanceof Animal; // true — vì Dog extends AnimalLưu ý: qua iframe/vm khác realm, instanceof có thể cho kết quả không như mong đợi.