Enums: Numeric and String Constants
Use enums to replace magic strings and numbers.
Welcome
Enums let you define a set of named constant values. They replace magic numbers and strings with readable names that TypeScript enforces.
Numeric Enums
By default, enum members are assigned auto-incrementing numbers starting at 0.
enum Direction {
Up, // 0
Down, // 1
Left, // 2
Right, // 3
}
console.log(Direction.Up); // 0All lessons in this course
- Typed Arrays: T[] and Array
- Readonly Arrays and Immutable Data
- Tuples: Fixed-Length Typed Arrays
- Enums: Numeric and String Constants