Enum
ELI5 — The Vibe Check
An enum is a named list of options that are all related. Instead of using magic strings like 'red', 'green', 'blue' everywhere, you define a Color enum and use Color.Red. No typos, no guessing what's valid.
Real Talk
An enum (enumeration) defines a set of named constant values. They make code more readable and prevent invalid states by constraining a variable to only the defined members. Most typed languages support them natively.
Show Me The Code
// TypeScript enum
enum Status {
Pending = "PENDING",
Active = "ACTIVE",
Closed = "CLOSED"
}
const orderStatus: Status = Status.Pending;
When You'll Hear This
"Use an enum for the order statuses instead of raw strings." / "The enum has four possible states."
Related Terms
Constant
A constant is a box you seal shut after putting something in. You can look inside any time you want, but you can't swap out what's in there.
Interface
An interface is like a job description. It says 'whatever fills this role must be able to do X, Y, and Z' without caring how they do it.
Type Inference
Type inference is the compiler being smart enough to figure out what type something is without you having to spell it out.
Variable
A variable is a named box where you store information.