-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBasicType.ts
More file actions
64 lines (56 loc) · 1.29 KB
/
BasicType.ts
File metadata and controls
64 lines (56 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//Boolean Example
let isDone: boolean = false;
//Number Example
let decimal: number = 6;
let hex: number = 0xf00d;
let binary: number = 0b1010;
let octal: number = 0o744;
//String Example
let color: string = "blue";
color = "red";
//Template String
let fullName: string = `Bob Bobbington`;
let age: number = 37;
let sentence: string = `Hello, my name is ${fullName}.
I'll be ${age + 1} years old next month.`;
//Array Example
let list: number[] = [1, 2, 3];
//Generics Way
let listGen: Array<number> = [1, 2, 3];
//Tuple Example
let mytuple = [10, "Hello", 20, 20, "World!"];
//Enums Example
enum Color {
Red,
Green,
Blue
}
let c: Color = Color.Green;
//Index will start at 0
enum ColorIndex {
Red = 1,
Green,
Blue
}
let c1: Color = Color.Green;
//Get Enum value using index
enum ColorGet {
Red = 1,
Green,
Blue
}
let colorName: string = Color[2];
//Any Example
let notSure: any = 4;
notSure = "maybe a string instead";
notSure = false; // okay, definitely a boolean
let notSureNew: any = 4;
notSure.ifItExists(); // okay, ifItExists might exist at runtime
notSure.toFixed(); // okay, toFixed exists (but the compiler doesn't check)
//Void Example
function warnUser(): void {
alert("This is my warning message");
}
//Null & Undefined Example
let u: undefined = undefined;
let n: null = null;