DEV Community

Discussion on: What's the Difference Between Nominal, Structural, and Duck Typing?

Collapse
 
jzombie profile image
jzombie

In JS / TS,

if (dog instanceof Dog) {
 // true
}

if (dog instanceof Person) {
 // false
}
Enter fullscreen mode Exit fullscreen mode

should let you know if dog actually inherits the relevant class, and it still works even if you created extension classes for dogs, as each extension will still be a dog.