-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenum.ts
55 lines (45 loc) · 1.01 KB
/
enum.ts
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
//An enum is a group of named constant values. Enum stands for enumerated type.
//An enum can be thought of as a class that has a fixed set of constants.
enum Weekday {
Sunday = 0,
Monday = 1,
Tuesday = 2,
Wednesday = 3,
Thursday = 4,
Friday = 5,
Saturday = 6,
}
function isItWeekend(day: Weekday) {
let isWeekend: boolean;
switch (day) {
case Weekday.Saturday:
case Weekday.Sunday:
isWeekend = true;
break;
default:
isWeekend = false;
break;
}
return isWeekend;
}
console.log(isItWeekend(Weekday.Saturday));
console.log(isItWeekend(Weekday.Sunday));
console.log(isItWeekend(Weekday.Monday));
console.log(isItWeekend(4));
//example of enum
enum ApprovalStatus {
draft,
submitted,
approved,
rejected
};
const approved =2;
const request = {
id: 1,
status: ApprovalStatus.approved,
description: 'Please approve this request'
};
if (request.status === ApprovalStatus.approved) {
console.log("send mail to client");
}
//example of enum