Whenever a variable is created, the intention is to assign some value to that variable but what type of value can be assigned to that variable is dependent upon the datatype of that Variable. In typeScript, type System represents different types of datatypes which are supported by TypeScript. The data type classification is as given below:
Built-in Datatypes: TypeScript has some pre-defined data-types-
|Built-in Data Type||keyword||Description|
|Number||number||It is used to represent both Integer as well as Floating-Point numbers|
|Boolean||boolean||Represents true and false|
|String||string||It is used to represent a sequence of characters|
|Void||void||Generally used on function return-types|
|Null||null||It is used when an object does not have any value|
|Undefined||undefined||Denotes value given to uninitialized variable||Any||any||If variable is declared with any data-type then any type of value can be assigned to that variable|
let a: null = null;
let b: number = 123;
let c: number = 123.456;
let d: string = ‘Geeks’;
let e: undefined = undefined;
let f: boolean = true;
let g: number = 0b111001; // Binary
let h: number = 0o436; // Octal
let i: number = 0xadf0d; // Hexa-Decimal
User-defined Data Types: Apart from built-in data types, user can also define its own data type. User-defined types include Enumerations (enums), classes, interfaces, arrays, and tuple.
NOTE: In built-in data types, any is a special data-type, also the super data-type of all data types. If a variable is declared with any data type then we can assign any type value to that variable.
let a: any = null;
let b: any =123;
let c: any = 123.456;
let d: any = ‘Geeks’;
let e: any = undefined;
let f: any = true;
- Identifiers and Keywords in TypeScript
- Hello World in TypeScript
- Variables in TypeScript
- TypeScript class
- Classes in TypeScript
- TypeScript Arrays
- TypeScript Tuples
- TypeScript Ambients Declaration
- TypeScript Union
- TypeScript String
- TypeScript Accessor
- Why use Question mark in TypeScript variable ?
- What are the differences between any vs Object in TypeScript?
- How to execute TypeScript file using command line?
- What is the difference between interface and type in TypeScript ?
- How to Import another TypeScript Files ?
- Difference between private keyword and private fields in TypeScript
- What is the difference between 'String' and 'string' in TypeScript ?
- How to Cast a JSON Object Inside of TypeScript Class ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.