CodePark/ questions / Classes & enums
START PRACTICINGPRACTICE
Frontend question · TypeScript › Classes & enums

What does this log?

enum Direction { Up, Down }
console.log(Direction[0], Direction.Down);
Up 1

It 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.