JavaScript Reserved Words
Reserved words (keywords) cannot be used as variable names, function names, or identifiers. They have special meaning in JavaScript.
JavaScript Keywords
Keywords are reserved words in JavaScript that have special meaning in the language syntax. These words are part of the JavaScript language itself and are used to define control structures, declarations, operators, and other fundamental language features. JavaScript has approximately 30-40 reserved keywords including break, case, catch, class, const, continue, debugger, default, delete, do, else, export, extends, finally, for, function, if, import, in, instanceof, let, new, return, super, switch, this, throw, try, typeof, var, void, while, with, and yield.
You cannot use keywords as variable names, function names, or any other identifiers in your code. Attempting to use a keyword as an identifier will cause a SyntaxError. For example, const function = 5 or let class = 'Math' will fail to parse. This restriction exists because the JavaScript parser uses these words to understand your code's structure. If you tried to name a variable if, the parser wouldn't know whether you're declaring a variable or starting a conditional statement.
Each keyword has a specific, special meaning in the JavaScript language that determines how the code is interpreted and executed. For example, if starts a conditional statement, function declares a function, return exits a function with a value, class defines a class, const declares a constant, for begins a loop, and try starts an error-handling block. Using keywords correctly is fundamental to writing JavaScript—they form the building blocks of the language's syntax and control flow.
JavaScript keywords are case-sensitive, meaning if is a keyword but If, IF, or iF are not. This is because JavaScript is entirely case-sensitive. While If would technically work as a variable name (it's not a keyword), using variations of keywords as identifiers is extremely poor practice and makes code confusing and error-prone. Stick to descriptive names that don't resemble keywords at all. This case-sensitivity also means typeof is a keyword but typeOf could be a valid identifier (though you shouldn't use it).
Avoid using reserved words and keywords as identifiers, property names, or in any context where they could cause confusion, even if technically allowed in some contexts. While modern JavaScript allows keywords as object property names (obj.class is valid), it's better to use different names to avoid confusion and potential issues with older environments or tools. Also avoid future reserved words like implements, interface, package, private, protected, public, and static in case they're added to the language. Using clear, descriptive identifiers that aren't keywords makes your code more readable and maintainable.
// Common keywords:
// break, case, catch, class, const
// continue, debugger, default, delete, do
// else, export, extends, finally, for
// function, if, import, in, instanceof
// let, new, return, super, switch
// this, throw, try, typeof, var
// void, while, with, yield
// Bad: using keyword as variable
// const function = 5; // Error!
// let class = "Math"; // Error!
// Good: use different names
const myFunction = () => {};
let className = "Math";
// Future reserved words (avoid):
// implements, interface, package, private
// protected, public, static