Recall & Review
beginner
What is a string enum in TypeScript?
A string enum is a special type in TypeScript where each enum member is initialized with a string literal. It helps group related string constants under one name.
Click to reveal answer
beginner
How do you declare a string enum in TypeScript?
Use the
enum keyword followed by member names and assign string values to each member, like:<br>enum Colors { Red = "RED", Green = "GREEN", Blue = "BLUE" }Click to reveal answer
intermediate
Why use string enums instead of numeric enums?
String enums provide readable values which make debugging and logging easier. They also avoid accidental numeric value changes and improve code clarity.
Click to reveal answer
intermediate
Can string enum members have computed values?
No, string enum members must be initialized with string literals or other string enum members. Computed or runtime values are not allowed.
Click to reveal answer
beginner
How do you access a string enum member's value?
You access it by using the enum name and member name, like
Colors.Red, which returns the string value assigned to that member.Click to reveal answer
Which of the following is a correct string enum declaration in TypeScript?
✗ Incorrect
Only option C assigns string values to enum members, which is required for string enums.
What will
Colors.Green return if enum Colors { Red = "RED", Green = "GREEN" }?✗ Incorrect
The member Green is assigned the string "GREEN", so accessing Colors.Green returns "GREEN".
Can you assign a number to a string enum member?
✗ Incorrect
String enum members must be initialized with string literals, not numbers.
Which is a benefit of using string enums?
✗ Incorrect
String enums provide clear string values that help with debugging and readability.
Are computed values allowed in string enums?
✗ Incorrect
String enums must have string literal values; computed values are not allowed.
Explain what a string enum is and why you might use it in TypeScript.
Think about grouping related strings under one name.
You got /3 concepts.
Describe how to declare and access members of a string enum with an example.
Show a simple enum with colors or directions.
You got /4 concepts.