JS Reserved Words
JavaScript Reserved Words: Keywords You Cannot Use as Names
JavaScript reserved words are identifiers the language already uses for its own syntax, such as if, return, class, and const. The parser expects these words to play a specific role, so using one as a variable or function name throws a SyntaxError before your code runs. This guide lists the reserved words, explains how strict mode and modules change the list, and shows safe naming alternatives.
Categories of Reserved Words
JavaScript reserves words across three groups:
Core language keywords:
break,case,catch,class,const,continue,debugger,default,delete,do,else,export,extends,false,finally,for,function,if,import,in,instanceof,new,null,return,super,switch,this,throw,true,try,typeof,var,void,while,with.Strict-mode reserved words:
implements,interface,let,package,private,protected,public,static,yield.Contextual keywords:
await(reserved insideasyncfunctions and modules) andenum(reserved for future use).
Two notes on this list:
enum is reserved in all code, even though JavaScript has no enum syntax. The language set it aside for possible future use.
null, true, and false are literals, but you still cannot use them as names.
Treat the MDN lexical grammar reference or the ECMAScript specification as the source of truth, because the list can change as the language evolves.
Why Reserved Words Cause a SyntaxError
JavaScript is parsed before it is executed. When the parser reads const class = "Math 101"; it sees class and expects a class declaration, not a variable name. It gives up immediately, so none of your code runs, not even the lines above the mistake.
You will see a message like Unexpected token 'class' in the browser console. The exact wording differs between browsers and Node.js, but the cause is the same.
Naming Alternatives When Keywords Clash
When modeling real-world concepts like CSS classes or school classes, pick clear descriptive names instead of fighting reserved words.
// Bad: class, default, and return cannot be variable names
// const class = "Math 101"; -> SyntaxError!
// Good: descriptive domain names
const courseClass = "Math 101";
const cssClassName = "btn-primary";
const defaultTheme = "light";
// Object property keys CAN use reserved words safely
const config = {
default: true,
return: "/dashboard",
};
console.log({ courseClass, cssClassName, defaultTheme, config });
How to Check Whether a Word Is Allowed
Open your browser's developer console or a Node.js REPL.
Try declaring a variable with the name: let package = 1;
If you get a SyntaxError, the word is blocked in that context.
Test again under "use strict"; or inside a module, because some words are only blocked there.
For example, let package = 1; runs in a classic sloppy-mode script but fails in strict mode and in ES modules. Code that works in a quick console test can still break once it moves into a module-based project.
Common Mistakes with JavaScript Reserved Words
Naming a variable class, default, or delete. Developers writing DOM helpers often type const class = el.className. Use className, or a descriptive name such as elementClass.
Overwriting built-in globals. Array, Object, JSON, and Error are not reserved words, so JavaScript may allow you to reuse them. Doing so hides the built-in object in that scope and causes confusing bugs. Avoid it.
Using await as a name in modules or async functions. It is reserved there, so const await = 1; throws a SyntaxError. In a classic non-module script outside an async function, it is technically allowed, but you should still avoid it to prevent surprises when the file becomes a module.
Relying on sloppy-mode leniency. Names like let, static, interface, and yield may work in old scripts but fail in modern code. Strict mode is the default in ES modules and class bodies, so plan for it.
For more on how strict mode changes the rules, see the MDN guide to strict mode. Related lessons on KoderSolution include JavaScript variables and JavaScript syntax.
Frequently Asked Questions
Can I use reserved words as object property names?
Yes, since ES5 you can write { default: "en", class: "card" } and access obj.default safely, though destructuring { class } still requires renaming via { class: className }.
Is undefined a JavaScript reserved keyword?
No, undefined is a read-only global property, not a reserved keyword—meaning shadowing it inside a local function (let undefined = 1) is legal in sloppy mode but strongly discouraged.
Why is enum reserved even though JavaScript has no enum syntax?
ECMAScript reserved enum early for potential future enum support (and TypeScript uses enum), so JavaScript engines reject const enum = 1;.
Conclusion
Never use the always-reserved keywords as variable or function names, and be careful with strict-mode words such as let, static, and yield. Pick descriptive names like courseClass or cssClassName; remember that property keys can use reserved words, and rename destructured values. Next, continue with JavaScript variables to practice naming rules.
Unlock Your
Full Potential.
Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With
Try it Yourself
Experiment with the code from this lesson in our interactive playground.
Test Your Knowledge
You've completed this section! Take a quick 5-question quiz to check your understanding.