Reserved Words in JavaScript

JavaScript, the language that animates web pages and brings them to life, has a well-defined set of reserved words. These words have special meanings within the language and cannot be used for your own variables, functions, or other identifiers. Understanding these reserved words is crucial for writing clean, functional, and error-free JavaScript code.

What are Reserved Words?

  • Reserved words are keywords pre-defined by JavaScript with specific purposes.
  • They act as the building blocks of the language, providing essential functionality for control flow, data types, and more.
  • Using a reserved word as a variable name or function name will result in a syntax error, preventing your code from running correctly.

Core Reserved Words

Here’s a breakdown of some fundamental reserved words in JavaScript:

Data Types:

  • boolean: Represents true or false values.
				
					let isLoggedIn = true; // Valid

				
			
  • number: Represents numerical values (integers, decimals).
				
					let age = 25; // Valid

				
			
  • string: Represents textual data enclosed in quotes.
     
				
					let name = "Alice"; // Valid

				
			

Control Flow:

  • ifelseelse if: Used for conditional execution based on boolean expressions.
				
					if (age >= 18) {
  console.log("You are eligible to vote");
} else {
  console.log("You are not eligible to vote");
}

				
			
  • forwhile: Used for looping through code blocks repeatedly based on conditions.
				
					for (let i = 0; i < 5; i++) {
  console.log(i); // Output: 0, 1, 2, 3, 4
}

				
			
  • break: Used to exit a loop prematurely.
  • continue: Used to skip to the next iteration of a loop.

Functions:

  • function: Used to define reusable blocks of code.
				
					function greet(name) {
  console.log("Hello, " + name + "!");
}
greet("Bob"); // Output: Hello, Bob!

				
			

return: Used to return a value from a function.

  • number: Represents numerical values (integers, decimals).
				
					let age = 25; // Valid

				
			

Statements

varletconst: Used for variable declaration. While var is the older approach, let and const are generally preferred due to better scoping and block-level declarations

				
					var, let, const: Used for variable declaration. While var is the older approach, let and const are generally preferred due to better scoping and block-level declarations
				
			

this: Refers to the current object context within a function.

Others

  • ininstanceof: Used for type checking and property existence checks.
  • delete: Used to delete properties from objects.

Advanced Reserved Words (ECMAScript 6 and beyond)

Newer versions of JavaScript (ECMAScript 6+) have introduced additional reserved words:

class: Used for defining object-oriented classes.

				
					class Person {
  constructor(name) {
    this.name = name;
  }

  greet() {
    console.log("Hello, my name is " + this.name);
  }
}

const person1 = new Person("John");
person1.greet(); // Output: Hello, my name is John

				
			
  • extends: Used for inheritance between classes.
  • super: Used to call methods from a parent class within a child class.
  • yield: Used for defining generator functions that can pause and resume execution. (More advanced topic)
  • asyncawait: Used for asynchronous programming with promises. (More advanced topic)

Future-Proofing with Reserved Words

While the core set of reserved words is unlikely to change drastically, staying updated with the latest JavaScript standards can help you avoid potential conflicts. It’s a good practice to check the official ECMAScript documentation for any additions or changes to the reserved words list.

Reserved Word Table

Reserved WordDescriptionIntroduced in
breakExits a loop prematurely.Core
caseUsed within switch statements for conditional branching.Core
catchUsed for handling exceptions in try...catch blocks.Core
classDefines object-oriented classes (ES6+).ES6
constDeclares constant variables (ES6+).ES6
continueSkips to the next iteration of a loop.Core
debuggerUsed for debugging purposes (triggers a breakpoint in development tools).Core
defaultUsed within switch statements as the default case.Core
deleteDeletes a property from an object.Core
doUsed with while for loop constructs.Core
elseUsed for alternative execution paths in conditional statements.Core
enumDefines enumerated data types (not recommended in modern JavaScript).Core (but discouraged)
exportUsed for exporting modules (ES6+).ES6
extendsUsed for inheritance between classes (ES6+).ES6
Boolean value representing false.Core
finallyUsed in try...catch blocks to execute code regardless of exceptions (ES6+).ES6
forUsed for looping through a block of code.Core
functionDefines reusable blocks of code.Core
ifUsed for conditional execution.Core
importUsed for importing modules (ES6+).ES6
inChecks if a property exists in an object.Core
instanceofChecks if an object is an instance of a class (ES6+).ES6
interfaceDefines the structure of an object (not directly used in JavaScript, but a future keyword).Future
letDeclares block-scoped variables (ES6+).ES6
nullRepresents the absence of a value.Core
package(Not used in browser JavaScript, reserved for future use in module systems).Future
privateDefines private members within classes (not directly used in JavaScript, but a future keyword).Future
protectedDefines protected members within classes (not directly used in JavaScript, but a future keyword).Future
publicDefines public members within classes (not directly used in JavaScript, but a future keyword).Future
returnExits a function and optionally returns a value.Core
staticDefines static methods and properties within classes (ES6+).ES6
superUsed to call methods from a parent class within a child class (ES6+).ES6
switchUsed for multi-way conditional branching.Core
thisRefers to the current object context within a function.Core
throwThrows an exception to signal an error.Core
1Boolean value representing true.Core
tryUsed for code that might throw exceptions (ES6+).ES6
typeofReturns the data type of a value.Core
varDeclares function-scoped variables (older approach, generally discouraged in favor of let and const).Core
void(The unary operator void has a special meaning, but the keyword itself is reserved and cannot be used as an identifier).Core
whileUsed for looping as long as a condition is true.Core
withUsed with caution due to scoping issues (generally discouraged).Core
yieldUsed for defining generator functions that can pause and resume execution (ES6+).ES6
asyncUsed for asynchronous programming with promises (ES6+).ES6
awaitUsed within async functions to wait for asynchronous operations (ES6+).ES6

Understanding reserved words forms the foundation for writing clean and maintainable JavaScript code. By familiarizing yourself with these keywords, you can leverage their built-in functionality to create efficient and robust applications. Remember, using a reserved Happy coding !❤️

Table of Contents

Contact here

Copyright © 2025 Diginode

Made with ❤️ in India