Skip to content

JavaScript Reserved Words

In JavaScript, certain identifiers are reserved words. These words have special meanings in the language and cannot be used as names for variables, functions, labels, or classes.

JavaScript is standardized by ECMA International as ECMAScript. The language has evolved significantly over the years:

  • ECMAScript 3 (ES3, 1999): The baseline for older JavaScript versions, widely supported.
  • ECMAScript 5 (ES5, 2009): Introduced significant improvements like strict mode, JSON support, and new Array methods. Fully supported in all modern browsers.
  • ECMAScript 6 (ES6) / ECMAScript 2015 (ES2015): A major update that introduced features like let and const, arrow functions, classes, modules, promises, template literals, and more. This is the foundation of modern JavaScript development.
  • Annual Releases (ES2016+): Since ES2015, ECMAScript has adopted an annual release cycle, introducing smaller sets of new features each year (e.g., ES2016, ES2017, …, ES2023). Modern browsers continuously update their JavaScript engines to support these new features.

When writing JavaScript today, you can generally assume support for ES2015 and many later features in modern browsers. For older environments or broader compatibility, transpilers like Babel can be used to convert modern JavaScript code into older, more widely compatible versions.

JavaScript Reserved Words (ECMAScript 2015 and later)

Section titled “JavaScript Reserved Words (ECMAScript 2015 and later)”

The following is a list of reserved words in modern JavaScript. You cannot use these as identifiers:

`await` (only in async functions)
`break`
`case`
`catch`
`class`
`const`
`continue`
`debugger`
`default`
`delete`
`do`
`else`
`enum` (still reserved, though not used by current JS)
`export`
`extends`
`false`
`finally`
`for`
`function`
`if`
`import`
`in`
`instanceof`
`new`
`null`
`return`
`super`
`switch`
`this`
`throw`
`true`
`try`
`typeof`
`var`
`void`
`while`
`with`
`yield` (only in generator functions)

Reserved in Strict Mode (and modules, which are implicitly strict):

Section titled “Reserved in Strict Mode (and modules, which are implicitly strict):”
`implements`
`interface`
`let`
`package`
`private`
`protected`
`public`
`static`

Note: arguments and eval are not strictly reserved words, but they have special behavior and should not be used as variable or function names in strict mode, and generally avoided as identifiers.

Besides reserved words, it’s also a good practice to avoid using names of built-in JavaScript objects, properties, and methods for your own identifiers to prevent confusion and potential errors.

Examples of built-in identifiers to be cautious with:

`Array`
`Date`
`Error`
`Function`
`Infinity`
`JSON`
`Math`
`NaN`
`Number`
`Object`
`Promise`
`Proxy`
`Reflect`
`RegExp`
`String`
`Symbol`
`Map`
`Set`
`WeakMap`
`WeakSet`
`Intl`
`console`
`document` (in browser environments)
`window` (in browser environments)
`isNaN`
`isFinite`
`parseFloat`
`parseInt`
`undefined`
`hasOwnProperty`
`toString`
`valueOf`

When JavaScript runs in a browser, global variables are properties of the window object. Many HTML element IDs or names can also become global properties on window (though this is considered bad practice to rely on). It’s best to avoid using common HTML tag names, attributes, event handler names, or properties of window, document, and other DOM objects as your global variable names.

Examples of HTML event handler names (avoid using them as function names directly assigned via attributes, e.g., onclick="myFunction()" is different from let onclick = ...):

`onabort`
`onblur`
`onclick`
`onerror`
`onfocus`
`onkeydown`
`onkeypress`
`onkeyup`
`onload`
`onmousedown`
`onmousemove`
`onmouseout`
`onmouseover`
`onmouseup`
`onreset`
`onresize`
`onscroll`
`onsubmit`
`onunload`

Modern Variable Declarations: let and const

Section titled “Modern Variable Declarations: let and const”

let and const, introduced in ECMAScript 2015 (ES6), are the standard way to declare variables in modern JavaScript, largely replacing var.

  • let: Declares a block-scoped local variable, optionally initializing it to a value. Variables declared with let can be reassigned.
  • const: Declares a block-scoped, read-only named constant. This means the variable’s identifier cannot be reassigned. For objects and arrays declared with const, their properties or elements can still be modified, but the variable itself cannot be made to refer to a different object or array.

Using let and const helps avoid common issues associated with var (like hoisting quirks and function-only scope) and leads to more maintainable and predictable code. They are fully supported in all modern JavaScript environments.

const PI = 3.14159; // Cannot be reassigned
// PI = 3; // This would cause an error
let counter = 0;
counter = counter + 1; // Allowed
if (true) {
const blockScopedVar = "I'm inside the block";
console.log(blockScopedVar);
}
// console.log(blockScopedVar); // Error: blockScopedVar is not defined outside the block