TypeScript Enums

Named constants.

✍️ 3 exercises + code challenge in this lesson

An enum groups related constants:

  • Numeric enum: enum Direction { Up, Down } (Up = 0, Down = 1)
  • String enum: enum Status { Active = "ACTIVE" }

Many teams prefer union literal types ("up" | "down") because they compile to no extra code.

Key Takeaways: TypeScript Enums

Mastering TypeScript Enums helps you write clean and reliable TypeScript code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.

TypeScript Enums Code Example

TypeScript
enum Status {
  Pending = "PENDING",
  Shipped = "SHIPPED",
  Delivered = "DELIVERED",
}

enum Level { Low, Medium, High }

const order: Status = Status.Shipped;
console.log(order, Level.High);
Output
SHIPPED 2
Free sign-in required · Google login available

TypeScript Enums Practice Exercises

Check what you learned in “TypeScript Enums”.

/ 3 solved
Fill in the blank

Declare an enum.

 Color { Red, Green, Blue }
✓ Correct! Not quite. Try again.
Multiple choice

In enum Level { Low, Medium, High }, what is Level.Medium?

✓ Correct! Not quite. Try again.
Code challenge

Create enum Role { Admin = "ADMIN", User = "USER" } and log Role.Admin.

Write the code in the live editor. Your answer is checked automatically.

Free sign-in required · Google login available

to save your exercise progress.
Finished this lesson?
Mark it complete to track your progress.

Stuck on something?

Ask the community in the CodesInTech forum.

Need a developer?

Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.

Explore Our Services