JavaScript Reserved Keywords

In JavaScript, reserved keywords are terms that are set aside by the language for its internal use. These words cannot be used as identifiers (like variable names, function names, etc.).

Using them as identifiers can result in errors or unexpected behavior.

Here is a list of reserved keywords in JavaScript:

JavaScript Reserved Keywords (ES5 and ES6)

  1. break – Terminates a loop or switch statement.
  2. case – Defines a case in a switch statement.
  3. catch – Defines the block of code to handle errors in try/catch.
  4. class – Declares a class (ES6).
  5. const – Declares a block-scoped, read-only variable (ES6).
  6. continue – Skips the current iteration of a loop and continues with the next.
  7. debugger – Invokes debugging.
  8. default – Specifies the default block in a switch statement.
  9. delete – Deletes an object’s property.
  10. do – Executes a block of code once, and then repeats the loop while a condition is true.
  11. else – Specifies the block of code to execute if a condition is false.
  12. export – Exports a module (ES6).
  13. extends – Extends a class or function (ES6).
  14. finally – Executes code after try/catch regardless of the result.
  15. for – Starts a for loop.
  16. function – Declares a function.
  17. if – Specifies a block of code to execute if a condition is true.
  18. import – Imports a module (ES6).
  19. in – Tests whether an object has a specific property.
  20. instanceof – Tests whether an object is an instance of a constructor.
  21. let – Declares a block-scoped variable (ES6).
  22. new – Creates a new instance of an object.
  23. return – Returns a value from a function.
  24. super – Refers to the parent class (ES6).
  25. switch – Evaluates an expression against multiple cases.
  26. this – Refers to the current object.
  27. throw – Throws an exception.
  28. try – Tests a block of code for errors.
  29. typeof – Returns the type of a variable.
  30. var – Declares a variable.
  31. void – Discards the expression's return value.
  32. while – Starts a while loop.
  33. with – Extends the scope chain for a block of code (deprecated).
  34. yield – Pauses and resumes a generator function (ES6).

Future Reserved Keywords (ES6+)

These keywords are reserved for potential future use and should be avoided:

  1. enum
  2. await (reserved for use within async functions)
  3. implements
  4. interface
  5. package
  6. private
  7. protected
  8. public
  9. static

Reserved in Strict Mode

When using strict mode in JavaScript ("use strict";), the following keywords are also reserved:

  1. arguments
  2. eval

Contextual Keywords

Some words in JavaScript are only reserved in certain contexts (such as in classes or modules):

  1. async – Used in async functions.
  2. await – Pauses async function execution until a Promise is resolved.
  3. of – Used in for...of loops.

These reserved words are part of the core syntax of JavaScript, and it is important to avoid using them as identifiers to prevent conflicts or unexpected behaviors.

Related posts

JavaScript Operator Precedence

JavaScript Syntax Tutorial with Examples

JavaScript String Search Methods: A Comprehensive Tutorial