Js Reserved Words in JavaScript
? JavaScript Reserved Words
Reserved words are keywords that JavaScript has set aside for its own syntax. You cannot use them as variable names, function names, or identifiers.
Using reserved words incorrectly leads to syntax errors.
Common JavaScript Reserved Words
| Reserved Words (ES5/ES6+) |
|---|
break |
continue |
do |
for |
instanceof |
switch |
var |
Future Reserved Words (may be reserved in strict mode or future versions)
| Future Reserved Words |
|---|
enum |
package |
public |
Examples: Illegal Usage
// Error: 'for' is a reserved wordvar for = 5; // SyntaxError// Error: 'class' is reservedfunction class() {} // SyntaxErrorGood Practice
Avoid using reserved words as identifiers.
When in doubt, pick descriptive variable/function names that are not reserved.
If you want, I can share a full list including reserved literals like null, true, false, or how strict mode affects reserved words!