JavaScript Reserved Words: The Complete List of Keywords
Contents
Reserved words are words that are part of JavaScript’s syntax, like if, class and return. You can’t use them as names for variables, functions, classes or parameters, because the parser would read them as the keyword instead.
Here’s the complete list for modern JavaScript, split into the groups that matter in practice.
Reserved keywords
These can never be used as identifiers, in any code: Some of them are operators rather than statements, like typeof, delete and void.
| Always reserved | |||
|---|---|---|---|
break |
case |
catch |
class |
const |
continue |
debugger |
default |
delete |
do |
else |
enum |
export |
extends |
false |
finally |
for |
function |
if |
import |
in |
instanceof |
new |
null |
return |
super |
switch |
this |
throw |
true |
try |
typeof |
var |
void |
while |
with |
true, false and null are technically literals, not keywords, but they’re reserved the same way. enum isn’t used by JavaScript yet; it’s reserved for the future (TypeScript uses it).
Reserved in strict mode
These are reserved only in strict mode. Since ES modules and classes are always strict, treat them as reserved everywhere:
implements |
interface |
let |
package |
private |
protected |
public |
static |
yield |
await is reserved inside ES modules and async functions, and yield inside generator functions.
Contextual keywords (not reserved)
These have a special meaning in specific places, but are perfectly valid names everywhere else:
as,from: inimportandexportstatementsasync: before a functionget,set: in object literals and classesof: infor...ofloopstarget,meta: innew.targetandimport.meta
Names to avoid anyway
Some names aren’t reserved, but using them causes errors or confusing bugs:
argumentsandeval: can’t be assigned or used as names in strict mode.undefined,NaN,Infinity: global values; shadowing them is legal but asking for trouble.name,status,top,parent,self,length: global browser properties. A top-levelvar namein a classic script changeswindow.name.- Old Java-style reserved words from ES1–3 (
abstract,boolean,byte,char,double,final,float,goto,int,long,native,short,synchronized,throws,transient,volatile): no longer reserved, but very old engines rejected them.
var status = 404;
console.log(typeof status); // "string": window.status converts it
What happens when you use one
The errors you'll see
Using a reserved word as a name is a syntax error, so the whole script fails to run, not just that line. The message depends on the browser.
const class = 'active';
// SyntaxError: Unexpected token 'class'
'use strict';
let interface = 'admin';
// SyntaxError: Unexpected strict mode reserved word
function save(default) {}
// SyntaxError: Unexpected token 'default'
Reserved words are fine as property names
Since ES5, object keys and property accesses can be any word, reserved or not. (The DOM’s element.className is named that way because element.class wasn’t allowed back then.) So obj.default and promise.catch() are perfectly valid.
const config = {
class: 'card', // OK as a key
default: true, // OK
new: false, // OK
};
config.class; // "card"
promise.catch(fn); // catch is a method name here
Renaming when destructuring
Data from an API often has keys like class or default. You can’t destructure them into variables of the same name, so rename them on the way out.
const { class: className, default: isDefault } = item;
// In imports, the module's default export
import { default as Chart } from './chart.js';
FAQ
How many reserved words does JavaScript have?
36 that are always reserved (including true, false, null and enum), plus 9 more in strict mode and await in modules and async functions.
Is “let” a reserved word?
Only in strict mode. In sloppy-mode scripts, var let = 1 still works for backwards compatibility, but don’t rely on it: modules and classes are always strict. How let, const and var are scoped and hoisted is a favorite interview topic; test yourself with this JavaScript scope and hoisting quiz.
Can I use a reserved word as a function name?
No. Function, variable, class and parameter names follow the same rules. Object property and method names can be reserved words.
Is “undefined” a reserved word?
No, it’s a read-only global property. Inside a function you can technically declare a variable called undefined, which is one reason old code wrote void 0 instead.