An enum gives related values names so code can refer to them consistently. Define one with `enum`, then access a member as `EnumName.Member`. An enum can also be used as a type. section 9.4
Use named values in a product list
In `src/index.ts`, `enum Product { Hat, Gloves, Umbrella }` defines three members. A tuple such as `[Product.Hat, 100]` pairs a product with its price; a `switch` on the first tuple value selects the matching price calculation. The names make each case clearer than an unexplained number. section 9.4
Numeric members start at 0 by default and increase by one: `Hat`, `Gloves`, and `Umbrella` have values 0, 1, and 2. You can assign a value explicitly—`Gloves = 20` makes the following `Umbrella` value 21—or use an expression. For a numeric enum, `Product[0]` looks up the name `Hat`. section 9.4.1
A string enum assigns a string to every member, as in `enum City { London = "London", Paris = "Paris" }`. Its values are easier to recognize in logs. String and number members can coexist, though that combination is not widely used. section 9.4.2
Watch for the limits of numeric enums:
- An enum-typed variable can accept a number with no matching member; looking up its name then yields `undefined`. String enums do not have this assignment problem. section 9.4.3
- `typeof` sees a numeric enum value as a JavaScript `number`, so it cannot distinguish the two in a type guard. section 9.4.3
- A regular enum produces a JavaScript object. A `const enum` instead substitutes values at compile time, but cannot support a numeric name lookup such as `Product[0]`. section 9.4.3
Enums also fit application commands: a `Commands` enum supplies the choices for an Inquirer.js prompt and the values checked when a user selects Quit or toggles completed to-do items. When only particular values are acceptable, an enum member can also appear within a literal value type. section 2.3.2 section 9.5.2






















