170
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)
- break – Terminates a loop or switch statement.
- case – Defines a case in a switch statement.
- catch – Defines the block of code to handle errors in try/catch.
- class – Declares a class (ES6).
- const – Declares a block-scoped, read-only variable (ES6).
- continue – Skips the current iteration of a loop and continues with the next.
- debugger – Invokes debugging.
- default – Specifies the default block in a switch statement.
- delete – Deletes an object’s property.
- do – Executes a block of code once, and then repeats the loop while a condition is true.
- else – Specifies the block of code to execute if a condition is false.
- export – Exports a module (ES6).
- extends – Extends a class or function (ES6).
- finally – Executes code after try/catch regardless of the result.
- for – Starts a for loop.
- function – Declares a function.
- if – Specifies a block of code to execute if a condition is true.
- import – Imports a module (ES6).
- in – Tests whether an object has a specific property.
- instanceof – Tests whether an object is an instance of a constructor.
- let – Declares a block-scoped variable (ES6).
- new – Creates a new instance of an object.
- return – Returns a value from a function.
- super – Refers to the parent class (ES6).
- switch – Evaluates an expression against multiple cases.
- this – Refers to the current object.
- throw – Throws an exception.
- try – Tests a block of code for errors.
- typeof – Returns the type of a variable.
- var – Declares a variable.
- void – Discards the expression's return value.
- while – Starts a while loop.
- with – Extends the scope chain for a block of code (deprecated).
- yield – Pauses and resumes a generator function (ES6).
Future Reserved Keywords (ES6+)
These keywords are reserved for potential future use and should be avoided:
- enum
- await (reserved for use within async functions)
- implements
- interface
- package
- private
- protected
- public
- static
Reserved in Strict Mode
When using strict mode in JavaScript ("use strict";
), the following keywords are also reserved:
- arguments
- eval
Contextual Keywords
Some words in JavaScript are only reserved in certain contexts (such as in classes or modules):
- async – Used in async functions.
- await – Pauses async function execution until a Promise is resolved.
- 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.