Recall & Review
beginner
What is an enum in TypeScript?
An enum is a special TypeScript feature that lets you define a set of named constants. It helps group related values under a single name.
Click to reveal answer
beginner
Why do we use enums instead of plain strings or numbers?
Enums make code easier to read and maintain by giving meaningful names to values. They also help catch errors early by restricting values to a fixed set.
Click to reveal answer
intermediate
How do enums improve code safety?
Enums restrict variables to only the predefined set of values, preventing invalid values and reducing bugs caused by typos or wrong inputs.
Click to reveal answer
beginner
Give a real-life example where enums are useful.
For example, days of the week can be an enum: Monday, Tuesday, etc. This avoids mistakes like misspelling 'Monday' or using invalid days.
Click to reveal answer
intermediate
What happens if you use plain strings instead of enums for fixed sets of values?
Using plain strings can lead to mistakes like typos, inconsistent values, and harder-to-maintain code because there is no central list of allowed values.
Click to reveal answer
What is the main benefit of using enums in TypeScript?
✗ Incorrect
Enums group related constants and give them meaningful names, improving code clarity.
Which problem do enums help prevent?
✗ Incorrect
Enums restrict values to a fixed set, preventing typos and invalid values.
How do enums improve code maintenance?
✗ Incorrect
Enums keep allowed values in one place, making updates and checks easier.
Which of these is a good use case for enums?
✗ Incorrect
Enums are great for fixed sets like user roles.
What happens if you assign a value not in the enum to an enum variable?
✗ Incorrect
TypeScript enforces enum values and shows errors for invalid assignments.
Explain why enums are useful in TypeScript and how they help prevent errors.
Think about how enums limit what values a variable can have.
You got /5 concepts.
Describe a real-life example where using an enum would make your code better.
Consider something with a small list of known options.
You got /4 concepts.