Recall & Review
beginner
What is an enum in TypeScript?
An enum is a way to define a set of named constants. It helps group related values under one name for easier use and better code clarity.
Click to reveal answer
beginner
How do you access a numeric enum member by its name?
You use dot notation with the enum name and member name, like
EnumName.MemberName.Click to reveal answer
intermediate
How can you get the name of an enum member from its numeric value?
TypeScript enums create a reverse mapping, so you can use
EnumName[value] to get the member name as a string.Click to reveal answer
beginner
What happens if you try to access an enum member that does not exist?
You get
undefined because the member name or value is not found in the enum.Click to reveal answer
intermediate
Can you access enum members using variables? How?
Yes, you can use bracket notation with a variable holding the member name or value, like
EnumName[variable].Click to reveal answer
How do you access the enum member 'Red' in
enum Color { Red, Green, Blue }?✗ Incorrect
You access enum members using dot notation: Color.Red.
What does
Color[0] return if enum Color { Red, Green, Blue }?✗ Incorrect
Numeric enums have reverse mapping, so Color[0] returns the member name 'Red'.
If you try
Color['Yellow'] and 'Yellow' is not a member, what is the result?✗ Incorrect
Accessing a non-existent enum member returns undefined.
Can you use a variable to access an enum member dynamically?
✗ Incorrect
Bracket notation allows dynamic access using variables.
What type of enum member access allows getting the member name from its value?
✗ Incorrect
Numeric enums have reverse mapping to get member names from values.
Explain how to access enum members by name and by value in TypeScript.
Think about how you use the enum name and member name or value.
You got /3 concepts.
Describe what happens when you try to access an enum member that does not exist.
Consider what JavaScript returns when a property is missing.
You got /3 concepts.