Recall & Review
beginner
What is reverse mapping in numeric enums in TypeScript?
Reverse mapping means you can get the name of an enum member by using its numeric value. TypeScript creates this automatically for numeric enums.
Click to reveal answer
intermediate
How does TypeScript create reverse mapping for numeric enums?
TypeScript creates an object where both the name-to-value and value-to-name mappings exist. For example, Enum[Enum.Value] returns the name as a string.
Click to reveal answer
beginner
Can reverse mapping be used with string enums in TypeScript?
No, reverse mapping only works with numeric enums. String enums do not have reverse mapping because string values are not unique keys.
Click to reveal answer
beginner
Example: What will be the output of this code?
enum Color { Red, Green, Blue }
console.log(Color[1]);The output will be "Green" because the numeric value 1 corresponds to the enum member Green.
Click to reveal answer
intermediate
Why is reverse mapping useful in TypeScript numeric enums?
It helps to get the name of an enum member from its numeric value, which is useful for debugging, logging, or displaying friendly names.
Click to reveal answer
What does reverse mapping in numeric enums allow you to do?
✗ Incorrect
Reverse mapping lets you use the numeric value to find the enum member's name.
Does reverse mapping work with string enums in TypeScript?
✗ Incorrect
Reverse mapping only works with numeric enums, not string enums.
Given
enum Status { Active = 1, Inactive, Pending }, what is Status[2]?✗ Incorrect
Since Active=1, Inactive=2, Pending=3, Status[2] returns "Inactive".
What type of object does TypeScript create for numeric enums?
✗ Incorrect
TypeScript creates an object with both mappings for numeric enums.
Why might reverse mapping be helpful when debugging?
✗ Incorrect
Reverse mapping helps by showing the enum member name from its numeric value.
Explain how reverse mapping works in numeric enums in TypeScript and why it is useful.
Think about how you can find the name if you only have the number.
You got /3 concepts.
Describe the difference between numeric enums and string enums regarding reverse mapping.
Consider how keys and values are stored in the enum object.
You got /3 concepts.