JavaScript Reserved Keywords
JavaScript Reserved Keywords
Reserved keywords are words that JavaScript uses for its own grammar. Words like if, for, let, function, and return have a fixed meaning in the language. JavaScript needs these words to understand your code.
Because JavaScript already uses these words, you cannot use them as names for your own variables, functions, or classes. If you try, JavaScript throws a SyntaxError and your code will not run.
This page gives you a complete list of every reserved keyword, explains what each one does, and shows you real examples so you understand them fully.
Why are keywords reserved?
Imagine if you could name a variable if. Then JavaScript would not know: does if mean your variable, or does it mean the start of an if-statement? It would be impossible to understand the code.
Reserving keywords solves this problem. JavaScript sees if and immediately knows: this is an if-statement, not a variable name.
Cannot Be Variable Names
You cannot use let, for, class, or any reserved keyword as an identifier.
Can Be Part of a Name
forEach, letValue, myClass are fine — the keyword is not alone.
About 40 Keywords
Modern JavaScript has around 40 reserved words. You will use most of them every day.
Future Keywords
Some words like enum are reserved for future use. Avoid them even if they work today.
What Happens If You Use a Keyword as a Name
What Happens If You Use a Keyword as a Name
If you try to use a reserved keyword as a variable name, JavaScript gives you a SyntaxError immediately — before your code even starts running. This is one of the easiest errors to fix once you know the rule.
1// ❌ These all cause SyntaxError — cannot use keywords as names:2// let let = 5; // SyntaxError: Unexpected strict mode reserved word3// let const = 5; // SyntaxError4// let for = 5; // SyntaxError5// let if = 5; // SyntaxError6// let class = 5; // SyntaxError7// let return = 5; // SyntaxError8// let new = 5; // SyntaxError910// ✅ But you CAN use a keyword as part of a longer name:11let letValue = 5; // 'let' is part of the name — OK12let myClass = 'Math'; // 'class' is part of the name — OK13let returnValue = 42; // 'return' is part of the name — OK14let forLoop = true; // 'for' is part of the name — OK15let newUser = 'Alice'; // 'new' is part of the name — OK1617console.log(letValue, myClass, returnValue, forLoop, newUser);1819// ✅ Keywords work fine as object property keys (not identifiers)20const obj = {21 if: 'this works',22 for: 'this works too',23 class: 'also works'24};25console.log(obj.if, obj.for, obj.class);
Declaration Keywords
Declaration Keywords
These keywords are used to declare (create) variables, functions, and classes. You use these every single day in JavaScript.
1// var — old way to declare a variable (avoid in modern code)2var oldScore = 50;3console.log('var:', oldScore);45// let — modern variable — can be changed later6let score = 100;7score = 95; // OK — let allows reassignment8console.log('let:', score);910// const — constant — cannot be reassigned11const MAX_SCORE = 100;12// MAX_SCORE = 200; // ❌ TypeError13console.log('const:', MAX_SCORE);1415// function — declares a function16function greet(name) {17 return 'Hello, ' + name + '!';18}19console.log(greet('Alice'));2021// class — declares a class (blueprint for objects)22class Animal {23 constructor(name) {24 this.name = name;25 }26 speak() {27 return this.name + ' makes a sound.';28 }29}30const cat = new Animal('Cat');31console.log(cat.speak());
| Keyword | What It Does | Example |
|---|---|---|
| var | Declares a function-scoped variable (legacy) | var name = 'Alice'; |
| let | Declares a block-scoped variable | let age = 25; |
| const | Declares a block-scoped constant | const PI = 3.14; |
| function | Declares a function | function add(a, b) { } |
| class | Declares a class | class User { } |
Control Flow Keywords
Control Flow Keywords
These keywords control which code runs and when. They let you make decisions, repeat actions, and jump between parts of your code.
1// if / else — run code based on a condition2const temperature = 28;34if (temperature > 35) {5 console.log('Very hot!');6} else if (temperature > 25) {7 console.log('Warm day.'); // this runs8} else {9 console.log('Cool or cold.');10}1112// switch / case / default / break — choose between many options13const day = 'Monday';1415switch (day) {16 case 'Monday':17 case 'Tuesday':18 case 'Wednesday':19 case 'Thursday':20 case 'Friday':21 console.log('Weekday — time to work!');22 break; // stop here — do not fall through to next case23 case 'Saturday':24 case 'Sunday':25 console.log('Weekend — time to rest!');26 break;27 default:28 console.log('Unknown day');29 break;30}
1// for — repeat code a set number of times2for (let i = 1; i <= 5; i++) {3 if (i === 3) continue; // skip 34 if (i === 5) break; // stop at 55 console.log('for:', i); // prints 1, 2, 46}78// while — repeat while a condition is true9let count = 3;10while (count > 0) {11 console.log('while countdown:', count);12 count--;13}1415// do...while — runs at least once, then checks condition16let attempts = 0;17do {18 attempts++;19 console.log('Attempt:', attempts);20} while (attempts < 3);2122// return — exits a function and gives back a value23function multiply(a, b) {24 return a * b; // stops the function and sends back the result25}26console.log('5 x 4 =', multiply(5, 4));
| Keyword | What It Does |
|---|---|
| if | Runs a block of code only when a condition is true |
| else | Runs when the if condition is false |
| switch | Chooses between many possible values |
| case | A single option inside a switch |
| default | The fallback option in a switch (when no case matches) |
| break | Exits a switch case or a loop immediately |
| continue | Skips the current iteration of a loop and goes to the next |
| for | Repeats code a set number of times |
| while | Repeats code while a condition is true |
| do | Runs code once, then repeats while a condition is true |
| return | Exits a function and optionally returns a value |
Error Handling Keywords
Error Handling Keywords
These keywords let you catch errors and handle them gracefully instead of letting them crash your program.
1// try — wrap code that might cause an error2// catch — runs if an error happens inside try3// finally — ALWAYS runs at the end, error or not45function parseUserData(jsonString) {6 try {7 const data = JSON.parse(jsonString); // might throw SyntaxError8 console.log('Parsed successfully:', data.name);9 return data;10 } catch (error) {11 console.log('Error:', error.message); // handle the error12 return null;13 } finally {14 console.log('Done — always runs.') // cleanup code15 }16}1718parseUserData('{"name": "Alice"}'); // works19parseUserData('{ bad json }'); // caught2021// throw — create your own error on purpose22function divide(a, b) {23 if (b === 0) {24 throw new Error('Cannot divide by zero!'); // throw keyword25 }26 return a / b;27}2829try {30 console.log(divide(10, 2)); // 531 console.log(divide(10, 0)); // throws32} catch (e) {33 console.log('Caught:', e.message);34}
Value Keywords
Value Keywords — true, false, null, undefined
These keywords represent built-in values in JavaScript. They are not strings — they are actual values with a specific meaning.
1// true and false — boolean values2const isLoggedIn = true;3const isAdmin = false;45if (isLoggedIn) {6 console.log('Welcome back!');7}8console.log('isAdmin:', isAdmin);910// null — intentional empty value (you set it on purpose)11let currentUser = null; // no user yet12console.log('currentUser:', currentUser); // null13console.log('type of null:', typeof null); // 'object' (a famous JS quirk)1415// undefined — a variable exists but has no value assigned16let notAssigned; // declared but not given a value17console.log('notAssigned:', notAssigned); // undefined1819function noReturn() {20 // no return statement21}22console.log('noReturn():', noReturn()); // undefined2324// null vs undefined25console.log(null == undefined); // true — both mean 'empty'26console.log(null === undefined); // false — different types
null and undefined are different
nullmeans: I intentionally set this to empty. A programmer did this on purpose.undefinedmeans: this variable exists but has never been given a value.
Use null when you want to say "no value here yet" in your own code. JavaScript uses undefined automatically when something has no value.
Object & Class Keywords
Object & Class Keywords
These keywords are used when working with objects and classes — the building blocks of object-oriented JavaScript.
1// class and extends — create a class that inherits from another2class Animal {3 constructor(name) {4 this.name = name; // 'this' refers to the current object5 }6 speak() {7 return this.name + ' makes a sound.';8 }9}1011class Dog extends Animal { // 'extends' inherits from Animal12 constructor(name) {13 super(name); // 'super' calls the parent constructor14 }15 speak() {16 return this.name + ' barks!';17 }18}1920// new — creates a new instance of a class or function21const animal = new Animal('Cat');22const dog = new Dog('Rex');2324console.log(animal.speak()); // Cat makes a sound.25console.log(dog.speak()); // Rex barks!2627// instanceof — checks if an object is an instance of a class28console.log(dog instanceof Dog); // true29console.log(dog instanceof Animal); // true — because Dog extends Animal30console.log(dog instanceof Array); // false3132// typeof — tells you the type of any value33console.log(typeof 42); // 'number'34console.log(typeof 'hello'); // 'string'35console.log(typeof true); // 'boolean'36console.log(typeof dog); // 'object'37console.log(typeof undefined); // 'undefined'3839// delete — removes a property from an object40const user = { name: 'Alice', age: 25, role: 'admin' };41console.log('before:', user);42delete user.role;43console.log('after delete:', user); // role is gone
Module Keywords
Module Keywords — import & export
These keywords let you split your code into separate files and share code between them. This is how modern JavaScript applications are structured.
1// ── math.js — EXPORTING ───────────────────────────────────23// Named export — you can have many of these4export const PI = 3.14159;56export function add(a, b) {7 return a + b;8}910export function multiply(a, b) {11 return a * b;12}1314// Default export — only one per file15export default function subtract(a, b) {16 return a - b;17}181920// ── app.js — IMPORTING ────────────────────────────────────2122// Import named exports — use exact name inside { }23import { PI, add, multiply } from './math.js';2425// Import the default export — any name works26import subtract from './math.js';2728// Import everything into one object29import * as MathUtils from './math.js';3031console.log(PI); // 3.1415932console.log(add(3, 4)); // 733console.log(subtract(10, 3)); // 734console.log(MathUtils.multiply(5, 4)); // 203536// Dynamic import — load a file only when needed37async function loadChart() {38 const { Chart } = await import('./chart.js');39 Chart.render();40}
Modules are the standard in modern JavaScript
Every big JavaScript project — React apps, Node.js APIs, Vue apps — uses import and export. You will use them every day once you start building real projects. They keep your code organized by splitting it into small, focused files.
Other Important Keywords
Other Important Keywords
1// in — checks if a property exists in an object2const person = { name: 'Alice', age: 25 };3console.log('name' in person); // true4console.log('salary' in person); // false56// for...in — loops over object property NAMES (keys)7for (const key in person) {8 console.log(key + ':', person[key]);9}1011// for...of — loops over VALUES in an iterable (array, string, etc.)12const fruits = ['apple', 'banana', 'cherry'];13for (const fruit of fruits) {14 console.log(fruit);15}1617// typeof — returns the type of a value as a string18console.log(typeof 42); // 'number'19console.log(typeof 'hello'); // 'string'20console.log(typeof true); // 'boolean'21console.log(typeof null); // 'object' (historical JS bug)22console.log(typeof undefined); // 'undefined'23console.log(typeof function(){}); // 'function'2425// void — evaluates an expression and returns undefined26console.log(void 0); // undefined27console.log(void 'anything'); // undefined (always undefined)2829// debugger — pauses code in browser DevTools (for debugging)30// Uncomment in browser to pause here:31// debugger;
1// async — marks a function as asynchronous (it can wait)2// await — pauses inside an async function until a promise finishes34async function fetchUserName(id) {5 // Simulate waiting 1 second for server response6 const result = await new Promise((resolve) => {7 setTimeout(() => resolve({ id, name: 'Alice' }), 100);8 });9 return result.name;10}1112// You must use await inside an async function13async function main() {14 const name = await fetchUserName(1);15 console.log('Fetched user:', name); // Alice1617 // Without async/await, you use .then() — older style18 fetchUserName(2).then(n => console.log('Then style:', n));19}2021main();22console.log('This runs while waiting for main() to finish.');
| Keyword | What It Does |
|---|---|
| in | Checks if a key exists in an object |
| of | Used in for...of to loop over values |
| typeof | Returns the type of a value as a string |
| instanceof | Checks if an object was created from a class |
| void | Evaluates an expression and returns undefined |
| delete | Removes a property from an object |
| debugger | Pauses execution in browser DevTools |
| async | Marks a function as asynchronous |
| await | Waits for a Promise to finish inside an async function |
| yield | Pauses a generator function and returns a value |
| with | Extends the scope chain (deprecated — do not use) |
Future Reserved Keywords
Future Reserved Keywords — Avoid These Too
Some words are reserved for future use — they are not keywords today, but JavaScript plans to use them later. If you use them as variable names today, your code may break when JavaScript updates.
Always avoid using these words as identifiers.
Complete Keyword List
Complete JavaScript Keyword List
Here is every reserved keyword in JavaScript. You cannot use any of these as a variable name, function name, or class name.
| Keyword | Category | What It Does |
|---|---|---|
| break | Control Flow | Exits a loop or switch immediately |
| case | Control Flow | A condition inside a switch statement |
| catch | Error Handling | Handles errors from a try block |
| class | Declaration | Declares a class (blueprint for objects) |
| const | Declaration | Declares a constant — cannot be reassigned |
| continue | Control Flow | Skips to the next loop iteration |
| debugger | Debugging | Pauses code in browser DevTools |
| default | Control Flow | Fallback in a switch when no case matches |
| delete | Operator | Removes a property from an object |
| do | Control Flow | Starts a do...while loop |
| else | Control Flow | Runs when an if condition is false |
| export | Modules | Makes a value available for import in other files |
| extends | Classes | Makes a class inherit from another class |
| false | Value | Boolean false value |
| finally | Error Handling | Runs after try/catch regardless of errors |
| for | Control Flow | Starts a loop |
| function | Declaration | Declares a function |
| if | Control Flow | Runs code only when a condition is true |
| import | Modules | Loads exports from another file |
| in | Operator | Checks if a property exists in an object |
| instanceof | Operator | Checks if an object was created from a class |
| let | Declaration | Declares a block-scoped variable |
| new | Operator | Creates a new object from a class or constructor |
| null | Value | Intentional absence of a value |
| return | Control Flow | Exits a function and returns a value |
| static | Classes | Defines a method that belongs to the class itself |
| super | Classes | Calls the parent class constructor or methods |
| switch | Control Flow | Chooses between multiple cases based on a value |
| this | Object | Refers to the current object |
| throw | Error Handling | Creates and throws an error |
| true | Value | Boolean true value |
| try | Error Handling | Wraps code that might throw an error |
| typeof | Operator | Returns the type of a value as a string |
| var | Declaration | Declares a function-scoped variable (legacy) |
| void | Operator | Evaluates expression and returns undefined |
| while | Control Flow | Repeats code while a condition is true |
| with | Scope | Deprecated — do not use |
| yield | Generator | Pauses a generator function |
| async | Async | Marks a function as asynchronous |
| await | Async | Waits for a Promise inside an async function |
Test Your Knowledge
Test Your Knowledge
What happens if you try to use a reserved keyword as a variable name?
Which of these variable names is NOT allowed?
What is the difference between null and undefined?
Which keyword do you use to stop a loop immediately?
What does the typeof keyword return for null?
Quick Reference
Reserved Keywords — Quick Reference
- 1Reserved keywords are words JavaScript uses for its own grammar. You cannot use them as variable or function names.
- 2Using a keyword as a name causes a SyntaxError — the code will not run at all.
- 3You CAN use a keyword as part of a longer name:
letValue,myClass,forLoopare all valid. - 4Keywords as object property keys are allowed:
obj.class,obj.if,obj.forall work. - 5Also avoid future reserved words like
enum,implements,interface— they may become keywords later. - 6
nullandundefinedare both 'no value' — butnullis intentional,undefinedis automatic. - 7
typeof nullreturns'object'— this is a historical bug. Use=== nullto check for null. - 8ES Modules and class bodies are always in strict mode — future keywords cause errors there.
Identifiers & Naming
The full rules for naming variables, functions, and classes in JavaScript.
Variables — let, const, var
How to store values in JavaScript and the key differences between let, const, and var.
Control Flow
if/else, switch, and loops — using control flow keywords in real programs.
Async & Await
How async and await work — the modern way to handle asynchronous JavaScript.
You know JavaScript reserved keywords!
You now know every reserved keyword in JavaScript, what each one does, and why you cannot use them as names. More importantly, you know how to USE these keywords to write real programs. Every keyword you learned here — if, for, function, class, async, await — is something you will use every single day as a JavaScript developer.
Try it in the Javascript Compiler
Run and experiment with Javascript code right in your browser — no setup needed.