Data Types represent different types of values supported by a language. This will check if a value is valid or not before assigning it to a variable. This ensures the behavior of the code.
Any Type
The any data type is the super data type of all the data types in TypeScript. It denotes a dynamic type. We can assign any type of value in this type of variable. We use this data type when we want to opt out of type checking for a variable.
Built-In Data Types
| Data Type | Keyword | Description |
|---|---|---|
| Number | number | It can be both integer and fraction value |
| String | string | Unicode character values |
| Boolean | boolean | logical values, true or false |
| Void | void | used as functions return types when we do not want to return anything |
| Null | null | leave the variable blank and not assign any value to it |
| Undefined | undefined | denotes value given to all uninitialized variables. |
There is a difference between null and undefined. They cannot only be used to assign values to the variables. A variable initialized with undefined means that the variable has no value or object assigned to it while null means that the variable has been set to an object whose value is undefined.
User-Defined Data Types
These includes Enums, classes, interfaces, arrays and tuples.
One thought on “Data Types in TypeScript”