Cyber Week

Save big!

All courses under $5 - for a limited time!

Code has been added to clipboard!

Reserved Words in JavaScript Coding

Reading time 4 min
Published Aug 8, 2017
Updated Oct 1, 2019

Choosing the wrong JavaScript keywords might be a reason you encounter various bugs. There is a whole list of JavaScript reserved words that you should not use, as they are used to execute the code or name JavaScript built-in objects. Some should be avoided because they come from other languages or Windows operating system.

In this tutorial, you will learn all about JavaScript reserved words. You will find extensive lists of all the words you should avoid using when creating variables, functions, and declarations.

JavaScript Reserved Words: Main Tips

  • There are some identifiers in JavaScript that are reserved, thus cannot be used as new variable or function names.
  • There are also words that are not forbidden to use as custom identifiers, but should be avoided because they already belong to built-in objects in JavaScript.

ECMAScript Versions

Before looking into the JavaScript reserved words, let's have a look at the release timeline of different versions of the language itself:

  • ECMAScript 3 - released in 1999, December.
  • ECMAScript 4 - abandoned.
  • ECMAScript 5 - released in 2009, December.
  • ECMAScript 6 - released in 2015, June (the latest official version of JavaScript).

As time goes by, ECMAScript 5 and 6 are finally getting the necessary support in all modern browsers.

List Of Terms to Avoid

The words specified below cannot be used as JavaScript keywords, names of variables, functions, or labels, because they are already reserved for others. For example, JavaScript yield is a keyword used to pause and resume the work of a generator function. Therefore, you can't apply this name to a new function you create.

Review the table carefully, and memorize the JavaScript reserved words:

arguments abstract break byte boolean
char const case class* catch
debugger delete default do continue
double else eval export* enum*
false finally final float extends*
function if goto implements for
in interface import* int instanceof
long null native new let
private return protected public package
static synchronized super* switch short
throw true throws transient this
typeof volatile var void try
yield with while

Note: You can see * symbol next to some of the words (for example, JavaScript enum). It marks words that are new in ECMAScript 5 and 6: for example, JavaScript super wasn't around until 2015.

It is also advised to avoid using names of JavaScript built-in objects, methods, and properties for your declarations:

Date hasOwnProperty eval function Array
isFinite length isNaN isPrototypeOf Infinity
NaN Object name Number Math
String valueOf toString undefined prototype

Java Reserved Words

Even if you're a newbie in coding, we're sure you already know the difference between JavaScript and Java. However, these two languages do tend to go hand in hand and be used together. For that reason, it may be best to avoid using Java objects and properties names for your JavaScript keywords, too.

See the list below to see the Java reserved words. You'll see it's rather short and easy to remember:

JavaArray java JavaPackage JavaObject getClass javaClass

Windows and HTML Terms

As you saw in the previous section, some word usage limitations also arise from using JavaScript with other languages and systems. JavaScript may also be used outside of HTML, on the system. Therefore, try not to use Windows objects and properties names for JavaScript variables and functions:

all area anchor anchors alert
blur clearInterval button checkbox assign
clientInformation confirm close closed clearTimeout
crypto defaultStatus decodeURI decodeURIComponent constructor
element embeds elements embed document
encodeURIComponent fileUpload escape event encodeURI
form innerHeight forms frame focus
layer location layers link innerWidth
navigate frameRate navigator frames mimeTypes
history offscreenBuffering image images hidden
opener outerWidth option outerHeight open
pageXOffset parseFloat pageYOffset parent packages
password prompt pkcs11 plugin parseInt
radio screenY reset screenX propertyIsEnum
secure setInterval select self scroll
status text submit taint setTimeout
top window unescape untaint textarea

It is also advised not to use event handler names for custom JavaScript keywords. This will let you avoid possible errors in your code:

onclick onfocus onerror onblur
onkeypress onmouseover onkeyup onkeydown
onmouseup onsubmit onmousedown onload

JavaScript Reserved Words: Summary

  • There are some words (JavaScript enum, static, public, etc.) that are considered reserved and should be avoided when declaring variables, functions and other custom declarations.
  • Some reserved words (like array or function) are part of JavaScript, including built-in object properties and HTML event listeners.
  • Some reserved words come from Java programming language, as well as Windows operating system.