Jobs
Blogs
Courses
Mentorship
Partners
For Employers
e2e logo

TypeScript( Enums)

mac

TypeScript Enums

  • An enum is a special "class" that represents a group of constants.
  • Enums come in two flavors string and numeric.

Numeric Enums - Default:

By default, enums will initialize the first value to 0 and add 1 to each additional value: 

Numeric Enums - Initialized:

You can set the value of the first numeric enum and have it auto increment from that:

Numeric Enums - Fully Initialized:

You can assign unique number values for each enum value. Then the values will not incremented automatically:

String Enums:

Enums can also contain strings  This is more common than numeric enums, because of their readability and intent.