Run ❯
Get your
own Node
server
❯
Run Code
Ctrl+Alt+R
Change Orientation
Ctrl+Alt+O
Change Theme
Ctrl+Alt+D
Go to Spaces
Ctrl+Alt+P
class Bird { fly() { console.log("Flying..."); } } class Fish { swim() { console.log("Swimming..."); } } function move(animal) { if (animal instanceof Bird) { // TypeScript knows animal is Bird here animal.fly(); } else { // TypeScript knows animal is Fish here animal.swim(); } } // Examples const bird = new Bird(); const fish = new Fish(); move(bird); // Outputs: Flying... move(fish); // Outputs: Swimming...
Flying... Swimming...