enum

A type that allows only a fixed list of named values, such as admin or user.

In more detail

Using an enum instead of free text stops typos and unexpected values. Validation libraries reject any value outside the list.

Examples

z.enum(["admin", "user"]) rejects any other role at run time.
Java: enum Light { RED, GREEN }; each constant is a single object, so == comparison is safe.
enum Light { RED, GREEN }
Enums make events easy to count and compare, but they lose detail: "Failure" does not say whether the password was wrong or the account unknown.

Related terms

Taught in

References

Certification courses