A past puzzle — fully playable. 4 attempts, hints on wrong guesses.
stdle-76.ts
1classAnimal{}
2classDogextendsAnimal{}
3constd:Animal=newDog()
4console.log(dinstanceofAnimal)
Narrowing
Answer & explanation
Console output
true
Why
`instanceof` checks whether the constructor`s prototype appears anywhere in the object`s prototype chain. Because `Dog` extends `Animal`, a `Dog` instance has `Animal.prototype` in its chain, so `d instanceof Animal` is true. TypeScript would narrow `d` to `Animal` here, which is already its declared type.