Bird
0
0

You want to create an enum for HTTP status codes with custom numeric values. Which is the correct way to declare it?

hard📝 Application Q8 of 15
Angular - TypeScript in Angular
You want to create an enum for HTTP status codes with custom numeric values. Which is the correct way to declare it?
Aenum HttpStatus = { OK = 200, NotFound = 404, InternalError = 500 }
Benum HttpStatus { OK: 200, NotFound: 404, InternalError: 500 }
Cenum HttpStatus { OK = 200, NotFound = 404, InternalError = 500 }
Denum HttpStatus -> { OK = 200, NotFound = 404, InternalError = 500 }
Step-by-Step Solution
Solution:
  1. Step 1: Recall enum syntax with assigned values

    Use enum Name { Key = value, ... } with equals signs inside braces.
  2. Step 2: Identify correct syntax

    enum HttpStatus { OK = 200, NotFound = 404, InternalError = 500 } matches correct syntax for numeric enum values.
  3. Final Answer:

    enum HttpStatus { OK = 200, NotFound = 404, InternalError = 500 } -> Option C
  4. Quick Check:

    Enum with assigned numbers uses '=' inside braces [OK]
Quick Trick: Use '=' inside braces for enum value assignments [OK]
Common Mistakes:
  • Using ':' instead of '='
  • Using '=' outside braces
  • Using arrows instead of braces

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes