In this section, we will learn what the keywords in JavaScript are and how they work.
Note: Before reading this section, you need to be familiar with the JavaScript variables in general.
What are Keywords in JavaScript?
The JavaScript language has a couple of special keywords that we use them for specific purposes in the language.
So because these keywords are reserved for the JavaScript itself, using them is forbidden as the name of a variable in the JavaScript programs.
JavaScript Reserved Words
In the list below you can see all these keywords:
abstract |
arguments |
await |
boolean |
break |
byte |
case |
catch |
char |
class |
const |
continue |
debugger |
default |
delete |
do |
double |
else |
enum |
eval |
export |
extends |
false |
final |
finally |
float |
for |
function |
goto |
if |
implements |
import |
in |
instanceof |
int |
interface |
let |
long |
native |
new |
null |
package |
private |
protected |
public |
return |
short |
static |
super |
switch |
synchronized |
this |
throw |
throws |
transient |
true |
try |
typeof |
var |
void |
volatile |
while |
with |
yield |
Since the ECMAScript 5/6, some of the keywords mentioned in the table above are removed. These words are mentioned in the table below:
Although this means we can use them as the name of a variable, it is recommended to not to. This is because still a considerable portion of people in the world are using the older version of web browsers that don’t support the `ECMAScript 5/6`.
Here’s the list:
abstract |
boolean |
byte |
char |
double |
final |
float |
goto |
int |
long |
native |
short |
synchronized |
throws |
transient |
volatile |
Also there are a couple of built-in Objects, methods, functions and properties in the JavaScript that we should avoid overriding them as the name of a variable.
Here’s the list of these JavaScript built in materials:
Array |
Date |
eval |
function |
hasOwnProperty |
Infinity |
isFinite |
isNaN |
isPrototypeOf |
length |
Math |
NaN |
name |
Number |
Object |
prototype |
String |
toString |
undefined |
valueOf |
In production environment, we usually mix other languages with the JavaScript. So you should also be careful and avoid using variable names that might be a special word in other programming languages that you use along with the JavaScript.
Example: using JavaScript reserved words
const name = "John Doe"; let age = 200; function printName(){ console.log(name+ " "+ age); }
Output:
John Doe 200
As you can see, we’ve used a few JavaScript keywords for their special purposes and not for the variable names!
Note: you’ll learn most of these keywords in the future sections.