Enum Numeric
Question
What does this enum produce? enum Direction { Up, Down, Left, Right }
Hint
Numeric enums are auto-incremented from 0 by default.
Explanation
Numeric enums auto-increment starting from 0. Direction.Up is 0, Direction.Down is 1, etc. You can set a custom start: enum Direction { Up = 1, Down, ... } makes Down = 2. Enums create a reverse mapping: Direction[0] returns "Up". Numeric enums are generally discouraged in favor of string enums or union types, because numeric values are less self-documenting and reverse mappings can cause bugs.
Related Resources
Related Lessons
- Enums
Learn enums.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.