0Pricing
TypeScript Academy · Lesson

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); // 0

All lessons in this course

  1. Typed Arrays: T[] and Array
  2. Readonly Arrays and Immutable Data
  3. Tuples: Fixed-Length Typed Arrays
  4. Enums: Numeric and String Constants
← Back to TypeScript Academy