JavaScript Reserved Words
14 April 2025 | Category: JavaScript
In JavaScript, reserved words are identifiers (like variable names or function names) that cannot be used because they are either part of the language syntax or reserved for future use.
Using these words as variable names or function names can lead to errors or unexpected behavior.
đ 1. Reserved Keywords (Used by JavaScript)
These are actively used in JavaScript syntax and must not be used as identifiers:
Category | Reserved Words |
---|---|
Control Flow | if , else , switch , case , default |
Loops | for , while , do , break , continue |
Declarations | var , let , const , function , class , extends , super |
Scope | this , return , yield |
Error Handling | try , catch , throw , finally |
Imports & Exports | import , export , from , as |
Others | new , delete , typeof , instanceof , void , in , with , await |
đ 2. Future Reserved Words
These are reserved for future versions of JavaScript and should be avoided:
enum, implements, package, protected, interface, private, public, static
They may not throw an error now but can break your code in the future when these become official features.
đ 3. Reserved in Strict Mode
When using "use strict";
in your JavaScript (recommended), the following words become reserved:
let, yield, eval, arguments
Strict mode has stricter parsing and error handling and doesnât allow reassigning or using these as identifiers.
đ 4. Literals (Also Reserved)
You cannot use the following JavaScript literals as identifiers:
null, true, false
These represent actual values in JavaScript and are not re-definable.
đ 5. Reserved Objects & Globals (Avoid Using as Variables)
Even though not strictly âreserved,â itâs a bad idea to use names of global objects or functions like:
Array, Object, Function, Number, String, Date, Math, JSON, RegExp, Promise, Set, Map, console, window, document
Using them as variables will override built-in features, which can break your app.
â Examples of Invalid Usage
let class = "MyClass"; // â SyntaxError: Unexpected token 'class'
function return() { } // â Invalid function name
const new = 5; // â 'new' is reserved
â Tips to Avoid Reserved Word Errors
- Stick to descriptive variable names.
- Use linters like ESLint to catch these issues early.
- Avoid using anything that “looks” like a JS keyword for your variables or functions.
đ Complete List of Reserved Words
You can check the full and up-to-date list of JavaScript reserved words in the ECMAScript specification.