enum - enumeration
- It's an object that stores related values
- The goal of enum is to signal to other engineers about a property
- The options are stored in capital first letter
- Enum is used to represent a fixed known set of options
// Enumeration of MatchResults
enum MatchResult {
HomeWin = 'H',
AwayWin = 'A',
Draw = 'D'
}
let win = 0;
let lose = 0;
for (let match of matches) {
if (MatchResult.HomeWin) win++;
else lose++:
}
// Type assertion
let match_result as MatchResult // consider match_result as one of the possible values of MatchResult
// Only accepts 'H', 'A' or 'D'
let match: MatchResult