0
0
Typescriptprogramming~20 mins

Reverse mapping in numeric enums in Typescript - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Enum Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of reverse mapping in numeric enum
What is the output of the following TypeScript code when compiled to JavaScript and run?
Typescript
enum Colors {
  Red = 1,
  Green,
  Blue
}

console.log(Colors[2]);
Aundefined
B"Green"
C2
D"Blue"
Attempts:
2 left
💡 Hint
Remember numeric enums create a reverse mapping from value to name.
Predict Output
intermediate
2:00remaining
Reverse mapping with custom numeric values
What will be logged by this code snippet?
Typescript
enum Status {
  Pending = 5,
  Active = 10,
  Completed = 15
}

console.log(Status[10]);
Aundefined
B"Pending"
C"Active"
D10
Attempts:
2 left
💡 Hint
Check which enum member has the value 10.
🧠 Conceptual
advanced
2:00remaining
Why reverse mapping does not exist for string enums
Why does reverse mapping not work for string enums in TypeScript?
ABecause string enums are not supported in TypeScript
BBecause string enum values are not unique and cannot be used as keys
CBecause string enums are compiled to objects without reverse mapping properties
DBecause TypeScript only generates reverse mapping for numeric enums
Attempts:
2 left
💡 Hint
Think about how TypeScript compiles numeric vs string enums.
Predict Output
advanced
2:00remaining
Output when accessing reverse mapping with invalid key
What is the output of this code?
Typescript
enum Directions {
  Up = 1,
  Down,
  Left,
  Right
}

console.log(Directions[5]);
Aundefined
B"Right"
C5
D"Up"
Attempts:
2 left
💡 Hint
Check if the enum has a member with value 5.
🧠 Conceptual
expert
3:00remaining
How reverse mapping affects enum object size
How does reverse mapping in numeric enums affect the size of the compiled enum object?
AIt doubles the number of properties because each numeric value maps back to its name
BIt reduces the size by removing duplicate keys
CIt has no effect on the size of the enum object
DIt triples the size because it adds extra metadata
Attempts:
2 left
💡 Hint
Think about how many keys exist in the compiled enum object compared to the number of enum members.