Multiple Types
Multiple Types
π¨βπΌ Sometimes a value can be one of several types. Union types let you express
this.
π¨ Open
and:
- Create a type for values that can be string or number
- Create a type for IDs that can be string or number
- Write functions that handle union types
typeof checks if a value is a string, number, boolean, or symbol. For
example, typeof value === 'string' returns true if value is a string.instanceof checks if an object was created from a particular class. For
example, value instanceof Error returns true if value is an Error object.