Reserved words are keywords that cannot be used as variable names, function names, class identifiers, or loop labels because they are reserved by JavaScript's grammar parser.
flowchart TD
Reserved["Reserved Words"] --> Current["Current Keywords (let, const, function, class, if, return, import)"]
Reserved --> FutureStrict["Future Reserved in Strict Mode (implements, interface, package, private, protected, public)"]
Reserved --> NullBool["Primitive Literals (null, true, false)"]
| Category | Keywords |
|---|---|
| Control Flow & Loops | if, else, switch, case, default, for, while, do, break, continue, return |
| Declarations & Scope | var, let, const, function, class, import, export, extends, super |
| Operators & Context | this, new, typeof, instanceof, void, delete, in, yield, await |
| Strict Mode Reserved | implements, interface, package, private, protected, public, static |
// Demonstrating Reserved Words and Safe Property Access
// 1. Invalid Variable Declarations (Un-commenting throws SyntaxError)
// const class = "Math"; // SyntaxError: Unexpected token 'class'
// let function = "Test"; // SyntaxError: Unexpected token 'function'
// 2. Safe Usage as Object Property Keys
// Modern ES6 allows reserved words as unquoted object property keys
const config = {
class: "UserAccount", // Allowed as object key!
default: true, // Allowed as object key!
delete: false // Allowed as object key!
};
console.log(`Object property 'class': ${config.class}`);
console.log(`Object property 'default': ${config.default}`);
// 3. Safe Destructuring with Renaming
const { default: isDefaultSetting } = config;
console.log(`Renamed reserved key: ${isDefaultSetting}`);
interface, package, or private as variable identifiers even in non-strict mode to ensure seamless TypeScript migration.default, rename them using alias syntax (import { default as myDefault } from "./mod.js").obj.delete or obj.class are valid in ES6+, but avoid them if possible for clarity.How do you safely rename a default import import { default } from "./module.js"?
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.