Enums vs Union Types (and const enums)

When to use enums, when to prefer string unions, and what const enums change.

F

Frontend Interview Team

February 08, 2026

1 min read
Enums vs Union Types (and const enums)

30‑second interview answer

In many frontend apps, prefer string union types for simple sets of values because they’re lightweight and tree-shake well. Enums can be useful, but they can add runtime output (unless const enum) and have interop considerations. Choose based on whether you need runtime values or just compile-time safety.


Union types (often the best)

type Status = 'idle' | 'loading' | 'success' | 'error';

Pros:

  • no runtime code
  • great with narrowing

Enums

enum Status {
  Idle = 'idle',
  Loading = 'loading',
}

Pros:

  • runtime object exists (can be used at runtime)

Cons:

  • can add bundle weight
  • numeric enums have weird reverse mapping

const enum

const enum inlines values at compile time.

const enum Mode {
  Dark = 'dark',
  Light = 'light',
}

Caution: it can complicate builds across packages.


Mini Q&A

Q1: When use union over enum?

  • when you don’t need runtime values.

Q2: What’s the issue with numeric enums?

  • reverse mapping and odd runtime behavior.

Q3: What does const enum do?

  • inlines values, no runtime object.

Summary checklist

  • I prefer unions for simple cases.
  • I know enums can add runtime code.
  • I understand const enum tradeoffs.