JavaScript reserved words are special identifiers built into the language grammar, such as if, return, class, and const. Because the parser expects these words to perform syntax roles, using them as variable or function names throws a SyntaxError.
JavaScript reserves words across three groups:
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.implements, interface, let, package, private, protected, public, static, yield.await (reserved inside async functions and modules) and enum (reserved for future use).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 });
class, default, or delete: Beginners writing DOM helpers often write const class = el.className, triggering an immediate SyntaxError. Use className instead.Array, Object, JSON, or undefined: Even where JavaScript does not throw a syntax error, naming a variable JSON or Error breaks built-in tools inside that scope.await as a variable name inside modules: In ES modules and async functions, await is reserved and throws a syntax error if used as an identifier.Yes, since ES5 you can write { default: "en", class: "card" } and access obj.default safely, though destructuring { class } still requires renaming via { class: className }.
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.
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;.
Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With
Experiment with the code from this lesson in our interactive playground.
You've completed this section! Take a quick 5-question quiz to check your understanding.