Basics of Type Script
1. To define a Variable.
There are two ways. Let and Var
Var a = 3;
Let b = 4;
The difference between Let and Var
2. Data type.
//Boolean
var bn: boolean = true
var bn:boolean = true; console.log(bn);
// Number type
var num:Number = 111;
var num2:Number = 3.14;
//String
var str:string = 'aaaa';
//Arrays
var arr:numer[] = [11,22,33,44];
var arr: Array<number> = [11,22,33,44];
//Enum
enum color {red, green, yellow, blue};
color[0] = red
example 2
enum color1 { red = 1, green =3, yellow = 5, blue}
color1[3] =green
color1[5] = yellow
color1[6] = blue
//Any
var tmp:any[] = ['aaa', 1111, 22, 3.4] //this will not throw error
//Void
function NAME(): string {
return "String";
} //this function must return type String as defined.
function NAME() : void {
}
3. Constant variable