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.
Named constants.
✍️ 3 exercises + code challenge in this lessonAn enum groups related constants:
enum Direction { Up, Down } (Up = 0, Down = 1)enum Status { Active = "ACTIVE" }Many teams prefer union literal types ("up" | "down") because they compile to no extra code.
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.
enum Status {
Pending = "PENDING",
Shipped = "SHIPPED",
Delivered = "DELIVERED",
}
enum Level { Low, Medium, High }
const order: Status = Status.Shipped;
console.log(order, Level.High);
SHIPPED 2
Check what you learned in “TypeScript Enums”.
Declare an enum.
Color { Red, Green, Blue }
In enum Level { Low, Medium, High }, what is Level.Medium?
Create enum Role { Admin = "ADMIN", User = "USER" } and log Role.Admin.
Free sign-in required · Google login available
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