enum
In JavaScript, the enum keyword is a reserved word that has no meaning in the language, so code can’t use it as a variable, function, or class name. ECMA-262 sets it aside as a future reserved word for a possible later feature.
Unlike the strict-mode reserved words, enum is reserved in every context, including sloppy-mode scripts. Using it as an identifier throws a SyntaxError when the code is parsed, before anything runs. Reserved words still work as property names, so { enum: true } and options.enum are valid.
TypeScript readers often look for enum because TypeScript has an enum declaration. That declaration is TypeScript syntax, not JavaScript, and a JavaScript engine rejects it with the same SyntaxError. JavaScript code usually models a fixed set of named constants with a frozen object built with Object.freeze(), or with symbol values.
JavaScript enum Keyword Examples
Using enum as a variable name is a SyntaxError even in sloppy mode, while a frozen object or an enum property name works fine:
> const enum = "status";
const enum = "status";
^^^^
Uncaught SyntaxError: Unexpected reserved word
> const Status = Object.freeze({ Active: "active", Archived: "archived" });
undefined
> Status.Active
'active'
> const schema = { enum: ["active", "archived"] };
undefined
> schema.enum
[ 'active', 'archived' ]
The first line fails because enum is reserved. The frozen Status object plays the role of an enumeration, and the schema object shows that enum is fine as a property name.
JavaScript enum Keyword Use Cases
- Explaining the
SyntaxErrorthat TypeScriptenumsyntax raises in a.jsfile - Naming an
enumproperty, as JSON Schema objects do - Choosing a replacement, such as a frozen object, for a set of named constants
Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.
By Leodanis Pozo Ramos • Updated Nov. 6, 2026