JavaScript Reserved Words

Welcome to TheCodingCollege.com! In JavaScript, reserved words are terms that the language has predefined for specific purposes, such as keywords, future use, or global objects. Understanding these reserved words is essential to avoid syntax errors and write clean, functional code.

In this guide, we’ll cover:

  • What reserved words are in JavaScript.
  • Lists of reserved words for ES5 and ES6.
  • Best practices for avoiding conflicts in your code.

What Are Reserved Words in JavaScript?

Reserved words in JavaScript are terms that you cannot use as:

  • Variable names
  • Function names
  • Object property names (though technically allowed, it’s discouraged for clarity)

These words are either:

  1. JavaScript Keywords: Used by the language to define actions, conditions, or structures.
  2. Future Reserved Words: Reserved for potential future JavaScript enhancements.
  3. Global Objects: Built-in objects that are always available, such as Math or Date.

List of JavaScript Reserved Words

1. JavaScript Keywords

These are part of the JavaScript language and serve specific functions.

Reserved WordPurpose
breakTerminates a loop or switch statement.
caseDefines cases in a switch statement.
catchHandles exceptions in try blocks.
classDeclares a class (ES6).
constDeclares a constant variable.
continueSkips to the next iteration of a loop.
debuggerPauses execution for debugging.
defaultDefines the default case in switch.
deleteDeletes an object property.
doStarts a do...while loop.
elseDefines the alternative block of an if statement.
exportExports a module (ES6).
extendsExtends a class (ES6).
finallyDefines cleanup code after try...catch.
forDeclares a for loop.
functionDeclares a function.
ifStarts a conditional statement.
importImports a module (ES6).
inChecks if a property exists in an object.
instanceofChecks if an object is an instance of a class.
letDeclares a block-scoped variable.
newCreates an instance of an object.
returnReturns a value from a function.
superRefers to the parent class (ES6).
switchStarts a switch statement.
thisRefers to the current object.
throwThrows an exception.
tryDefines a block of code to test for errors.
typeofReturns the data type of a variable.
varDeclares a variable (function-scoped).
voidEvaluates an expression without returning a value.
whileStarts a while loop.
withExtends the scope chain (deprecated).
yieldPauses and resumes a generator function (ES6).

2. Future Reserved Words

These are reserved for potential future use in JavaScript and should be avoided as variable names.

Reserved WordNotes
enumReserved for enums.
awaitReserved for async operations.

3. Global Objects

While not technically “reserved,” these are part of the JavaScript runtime and shouldn’t be overwritten.

Global ObjectPurpose
ArrayRepresents an array.
DateRepresents date and time.
MathProvides mathematical functions.
JSONHandles JSON data.
PromiseRepresents asynchronous operations.

Best Practices to Avoid Reserved Word Conflicts

  1. Use Descriptive Names
    Always use meaningful variable and function names to avoid conflicts. // Avoid let class = 'Math'; // Error // Use let className = 'Math';
  2. Follow Naming Conventions
    Use camelCase for variables and functions, and PascalCase for classes.
  3. Lint Your Code
    Use tools like ESLint to detect potential issues with reserved words.
  4. Keep Updated
    Stay informed about new ECMAScript features to avoid using newly reserved words.

Why Learn About Reserved Words with TheCodingCollege.com?

At TheCodingCollege.com, we aim to provide:

  • Clear explanations of JavaScript concepts.
  • Practical examples to help you avoid errors.
  • Tutorials designed to improve your coding skills.

Understanding reserved words ensures your code is error-free and compatible across environments.

Conclusion

Reserved words in JavaScript play a critical role in defining the structure and functionality of the language. Avoiding their misuse ensures that your code is clean, maintainable, and free from syntax errors.

Leave a Comment