Course contentsShow
← TypeScript
Lesson 498 of 1,79612. EnumsFree lesson

When to Choose Numeric vs String Enums

Decide between numeric and string enums based on serialization needs and debuggability.

When to Choose Numeric vs String Enums

What you'll learn: How to decide whether to use numeric or string enums based on your specific needs for serialization and debugging.


The Core Decision

You've learned both numeric and string enums — but when should you choose one over the other? The decision boils down to two main factors: serialization (saving/sending data) and debuggability (how readable values are during development).


Choose String Enums When...

You Need Readable Serialized Data

String enums shine when your enum values get saved to databases, sent over APIs, or logged to files. The actual string value is stored, making debugging and data inspection much easier:

enum LogLevel {
  Error = "ERROR",
  Warning = "WARNING",
  Info = "INFO"
}

// Saved to database: { level: "WARNING" }
// Readable without looking up enum definition!

Debuggability Matters Most

In logs, network requests, or JSON responses, seeing "ERROR" is instantly meaningful. Seeing 0 requires you to check the enum definition.


Choose Numeric Enums When...

You Need Compact Storage

Numeric enums use less space in memory and serialized formats:

enum Status {
  Pending,    // 0
  Active,     // 1
  Completed   // 2
}

// Stored as: { status: 1 } — smaller than "Active"

You Want Reverse Mapping

Only numeric enums provide reverse mapping, letting you look up names from values at runtime.


The Rule of Thumb

Default to string enums for most application code — clarity beats brevity. Use numeric enums when storage size matters or you specifically need reverse mapping.

Key Takeaway: Choose string enums for readable serialization and easier debugging; choose numeric enums for compact storage and reverse mapping capabilities.