JavaScript Keywords have a special meaning in the context of a language. They are part of the syntax of JavaScript. These are reserved words and we cannot use them as JavaScript Identifier names. Using them will result in a compile error.
| Reserved Words | ||
|---|---|---|
| arguments*** | await** | break |
| case | catch | class |
| const | continue | debugger |
| default | delete | do |
| else | enum | export |
| extends | false* | finally |
| for | function | get*** |
| if | import | in |
| instanceof | new | null* |
| return | set*** | super |
| switch | this | throw |
| true* | try | typeof |
| var | void | while |
| with | yield | |
* The null , true , and false are not keywords but literals, but we cannot use them as identifiers as they have special meaning.
*** We cannot use , await only when we use it inside a Module.
*** , arguments, , get, , set are not keywords, but they do have special meaning in some contexts. Hence better avoid them
You cannot use the following reserved keywords only if you enable strict mode.
For Example
The following works although we used let as the variable name.
let let=2;
console.log(let) //2
But enabling the strict mode will result in an error.
"use strict"
let let=2; //Unexpected strict mode reserved word
console.log(let)
The following is a list of strict mode-only reserve words.
| Strict Mode Reserved Words | ||
|---|---|---|
| arguments | eval | implements |
| interface | let | package |
| private | yield | |
The following keywords do not have any special meaning now. But they may be used in some times in the future. Hence they cannot be used as identifiers.
| Reserved Words | ||
|---|---|---|
| abstract | boolean | byte |
| char | catch | double |
| float | goto | int |
| long | native | short |
| synchronized | throws | transient |
| volatile | ||
The NaN, Infinity, and undefined are not reserved keywords in JavaScript But you must avoid using them. They are properties of the global object and have special meanings. Although they are immutable & read-only properties, JavaScript does not throw any errors if you declare them in the global scope.
Read More