mirror of
https://github.com/kamranahmedse/developer-roadmap.git
synced 2025-08-05 08:47:42 +02:00
Fix instanceOf mistake (#4322)
instanceof is a runtime check and interface and types don't exist during runtime. Also TypeScript has a structural type system, which means that they are matched according to the structure of the object and types - not according to instances. For example: interface Person { name: string; age: number } const person = { name: "Ken", age: 25 } if (person instanceof Person) // Error
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
# instanceOf operator
|
# instanceOf operator
|
||||||
|
|
||||||
The `instanceof` operator is a way to narrow down the type of a variable. It is used to check if an object is an instance of a class, interface, or type.
|
The `instanceof` operator is a way to narrow down the type of a variable. It is used to check if an object is an instance of a class.
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
class Bird {
|
class Bird {
|
||||||
|
Reference in New Issue
Block a user