Data type
|
Keyword
|
Description
|
---|---|---|
Number | number | Double precision 64-bit floating point values. It can be used to represent both, integers and fractions. |
String
|
string
|
Represents a sequence of Unicode characters |
Boolean
|
boolean
|
Represents logical values, true and false |
Void | void | Used on function return types to represent non-returning functions |
Null
|
null
|
Represents an intentional absence of an object value. |
Undefined
|
undefined
|
Denotes value given to all uninitialized variables |
TypeScript provides data types as a part of its optional Type System. The data type classification is as given below −
let a: number //e.g 1, 2, 3 let b: boolean //e.g true, false let c: string //e.g "abel agoi" let d: any //this can take any other types let e: number[] //array of numbers e.g [1, 3, 54] let f: any[] //any array e.g [1, "abel agoi", true]
In javascript, we can declare a function like below:
let log = function (message) {
console.dir(message);
}
You can also use the arrow function (=>) to achieve the same thing in typescript like below
let log = (message) => { //we simply remove the function console.dir(message); }
//above can even be shorten to let log = (message) => console.dir(message);
//and if you are only passing one parameter, it can be shorten to let log = message => console.dir(message); //not readable though
Comments
Post a Comment