๐ Reserved Keywords in JavaScript: The Untouchable Words of JavaScript

Imagine youโre playing football on a school field. There are some areas you just canโt enter โ like the teachersโ stand or the refereeโs zone. No matter how much you want to, those spaces are off-limits.
Thatโs exactly how reserved keywords work in JavaScript. They are special words that the language itself uses, so programmers cannot use them as names for variables, functions, or identifiers.
If you try, JavaScript will blow the whistle ๐จ and throw an error.
๐ท๏ธ What Are Reserved Keywords?
Reserved keywords are predefined words that have a fixed meaning in the JavaScript language.
For example:
let let = 5; // โ Error: "let" is reserved
Here, let is already used by JavaScript to declare variables. Trying to use it as a variable name confuses the engine.
๐ Categories of Reserved Keywords
Reserved words in JavaScript can be grouped into categories depending on how they are used.
1. Current JavaScript Keywords
These are words we use every day in modern JavaScript. They control logic, structure, and behavior.
Examples:
- Declarations:
var,let,const,function,class - Control flow:
if,else,switch,case,default,do,while,for,break,continue - Error handling:
try,catch,finally,throw - Specials:
return,new,delete,typeof,instanceof,this,super
2. Future Reserved Words
ECMAScript (the standard for JavaScript) keeps aside certain words for possible future use. You shouldnโt use them either, even if they donโt do anything yet.
Examples:
enum, implements, interface, package, private, protected, public, static, yield
3. Strict Mode Reserved Words
When you use strict mode ("use strict";), JavaScript becomes extra strict and protects certain words.
Reserved in strict mode:
let, static, implements, interface, package, private, protected, public
4. Null, Boolean, and Literals
You also cannot use certain literal values as names:
nulltrue,false
๐ Why Should You Care?
- Avoid Errors If you mistakenly use reserved words as identifiers, your program will crash.
const class = "JSS3"; // โ SyntaxError
-
Future-Proofing Even if some reserved words arenโt active now, future JavaScript versions may use them. So avoid them entirely.
-
Clarity Reserved keywords have strong meanings in the language. Using them wrongly makes your code confusing to read.
โ Best Practices
- Always choose descriptive names: e.g., use
studentNameinstead ofclass. - Use code editors or linters (like ESLint) โ theyโll highlight reserved words when misused.
- Stay updated with ECMAScript changes, as some new reserved words might be added in future.
๐ Review โ Fill in the Gaps
- Reserved keywords are special words that cannot be used as __ names in JavaScript.
- The word
letis used to declare a __ in JavaScript. - Using
classas a variable name will cause a __ error. - Words like
enum,package, andpublicare __ reserved for future use. - When
"use strict";is enabled, JavaScript blocks even more __ words. - The values
true,false, andnullare examples of __ that cannot be used as identifiers. - Reserved words like
if,else, andswitchare used in controlling program __. - JavaScript protects keywords to avoid __ in the engine.
- A linter like __ can highlight misused reserved keywords.
- Instead of using
classas a variable, a better choice would be __.