When a variable is declared some part of memory is reserved. But how much memory will be reserved. It depends upon the data type of the variable. i.e. how much memory will be reserved and which type of data can be stored in reserved memory is depends upon data type of the variable. The Type System of a language represents these data types.
Data types in TypeScript:
- Any Type: represents the super type of all data types in TypeScript. TypeScript provides the compile time data type-checking for the variables. In some situation we may not know what type of value for variable will come. These values may come from dynamic content e.g. from the user. In such cases, we want to opt-out of type-checking and let the values pass through compile-time checks. The any type is used for these variables.
- Built-in types:
- User-defined types: include Enumerations (enums), classes, interfaces, arrays, and tuple.
Data type | Keyword | Description |
Number | number | It represents a double precision 64-bit floating point values which can be used to represent both integers and fractions. |
String | string | It represents a sequence of characters. |
Boolean | boolean | It represents logical values true and false. |
Void | void | It is used on function return types to represent non-returning functions. |
Null | null | It is used to represent an intentional absence of an object value. |
Undefined | undefined | It represents uninitialized variables. |