Enum
PronunciationEE-num
Definition
An enum (enumeration) is a type with a fixed set of named values, such as PAID, UNPAID and UPCOMING.
Where you hear it
In code that models statuses, roles or options, and in reviews that replace repeated strings with a named type.
Examples
Use an enum for the payment status instead of raw strings.
The database column only accepts the values defined in the enum.
The order status enum stops a typo such as PAYED from reaching the database.
Common mistake
Scattering the same string, like "paid", across the code. One typo creates a silent bug; an enum lets the tools catch it.
Don't confuse with
A constant, which is a single fixed value. An enum groups related constants into one type.
Say it at work
- In a meeting or chat
Replace those magic strings with an enum.
- In an email or ticket
Adding a new status means adding one enum member.
Keep exploring
More in Programming Fundamentals