Bird
0
0

What is wrong with this enum declaration in Angular?

medium📝 Debug Q14 of 15
Angular - TypeScript in Angular
What is wrong with this enum declaration in Angular?
enum Color { Red = 'red', Green, Blue = 'blue' }
AEnum values cannot be strings
BEnum names must be lowercase
CEnum must have at least three values
DYou cannot mix string and numeric enum values without explicit assignment
Step-by-Step Solution
Solution:
  1. Step 1: Analyze enum value types

    Mixing string and numeric enum members without explicit values causes errors.
  2. Step 2: Identify the problem in the code

    Green has no assigned value after Red is string 'red', so it tries to auto-assign a number, which is invalid.
  3. Final Answer:

    You cannot mix string and numeric enum values without explicit assignment -> Option D
  4. Quick Check:

    Mixed enum types need explicit values [OK]
Quick Trick: Assign all string values explicitly to avoid mixing errors [OK]
Common Mistakes:
  • Assuming enum names must be lowercase
  • Thinking enums can't have string values
  • Believing enums require minimum count

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes