enum Direction { Up, Down }
console.log(Direction[0], Direction.Down);
Up 1It logs Up 1. Numeric enums start at 0 and get a reverse mapping from value to name. So Direction[0] is the name "Up", and Direction.Down is the value 1.0 1 is wrong because Direction[0] reads the reverse mapping, not a value. Note that string enums do not get reverse mappings.
Read more
- Enums (https://www.typescriptlang.org/docs/handbook/enums.html)typescriptlang.org