capypad
0 day streak
typescript / beginner
Snippet

Numeric Enums

Enums allow a developer to define a set of named constants, making it easier to document intent or create a set of distinct cases.

snippet.ts
typescript
1
2
enum Response { No = 0, Yes = 1 }
const userResponse = Response.Yes;
Breakdown
1
enum Response { No = 0, Yes = 1 }
Defines the enum with custom numeric values for each member.
2
const userResponse = Response.Yes;
Assigns the value 1 to the variable using the enum member name.