Reserved Keywords in JavaScript

javascript reserved words guide
10 November 2024

In the world of JavaScript programming, there is a concept known as "reserved keywords" which holds significant importance. Reserved keywords refer to a set of keywords that are defined in the programming language and you cannot use them as variable names, identifiers, or any other name. The reason for this issue is that these keywords have specific meanings in the programming language and using them as variable names could lead to errors in the code.

These keywords may include conditional operators, data types, functions, and other meaningful constructs that have specific uses in JavaScript. Therefore, recognizing and understanding these keywords is essential for every JavaScript programmer. You can think of them like the signs in a driving guide that, if you don’t pay attention to, could lead to accidents or at least problems in your coding.

One of the good ways to avoid inappropriate usage of reserved keywords is to always keep a list of these words handy and when assigning a new variable or identifier, refer to this list. In some development environments like Visual Studio Code, improper use of these keywords will often alert you, so it’s better to follow basic principles to avoid them.

There are many educational resources available online that can greatly assist in getting familiar with these keywords and using them well. So, if you are a JavaScript programmer or intend to learn JavaScript, pay attention to this concept.

Continuing, here is a list of reserved keywords that are commonly used in JavaScript for your reference:


let returnValue = 5; // Error, return is a reserved keyword
class = 'content';   // Error, class is a reserved keyword
const new = true;    // Error, new is a reserved keyword

Line-by-line explanation of the code above:

let returnValue = 5; – This line attempts to create a variable named returnValue, but since return is a reserved keyword, it results in an error.
class = 'content'; – This line tries to define a variable named class, which causes an error because class is a reserved keyword.
const new = true; – This line also causes an error because new is a reserved keyword used to create objects.

FAQ

?

Why can't we use reserved keywords as variable names?

?

Where can I find a list of reserved keywords in JavaScript?

?

Are all reserved keywords the same across different versions of JavaScript?