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.
Table of Contents
List of Reserved Words
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
List of Strict Mode Reserved Words
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.
1 2 3 4 | let let=2; console.log(let) //2 |
But enabling the strict mode will result in an error.
1 2 3 4 5 6 | "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 | protected | public |
static | yield |
Future Reserved Words
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 | double | final |
float | goto | int |
long | native | short |
synchronized | throws | transient |
volatile |
Other Keywords that you must avoid
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.
good
seems so good
Thanks