Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

JavaScript retains keywords


May 06, 2021 JavaScript


Table of contents


JavaScript retains keywords


Keep keywords that are meant to be words that will be retained as future keywords.

In JavaScript, some identifiers are reserved keywords and cannot be used as variable or function names.


JavaScript standard

All modern browsers fully support ECMAScript 3 (ES3, the third version of JavaScript, since 1999).

ECMAScript 4 (ES4) failed.

ECMAScript 5 (ES5, released in 2009) is the latest official version of JavaScript.

As time goes on, we begin to see that all modern browsers are fully supported by ES5.


JavaScript retains keywords

Javascript's reserved keywords cannot be used as variables, tags, or function names. Some reserved keywords are used as Javascript extensions later.

abstract arguments 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

The tagged keywords are newly added in ECMAScript5.


JavaScript objects, properties, and methods

You should also avoid using the names of objects, properties, and methods built into JavaScript as variables or function names for JavaScript:

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


Java retains keywords

JavaScript is often used with Java. You should avoid using some Java objects and properties as JavaScript identifiers:

getClass Java JavaArray javaClass JavaObject JavaPackage


Windows retains keywords

JavaScript can be used outside of HTML. It can be used as a programming language in many other applications.

In HTML, you must (and you should do the same for portability) avoid using the names of HTML and Windows objects and properties as variables and function names for Javascript:

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


HTML event handle

In addition, you should also avoid using the name of the HTML event handle as a variable and function name of JavaScript.

Example:

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

Notice: In JavaScript, the keyword cannot be used as a variable name or a function name, otherwise an error message may be obtained, such as "Identifier Expected", "" Identifier Expected "(Item, Design Identifier)."



Non-standard JavaScript

In addition to keep keywords, there are also some non-standard keywords in JavaScript implementation.

One instance is const Keywords are used to define variables.Some JavaScript engines treat const as synonyms of VAR.Other engines use the Const as the definition of a read-only variable.

Const is an extension of JavaScript.The JavaScript engine supports it in Firefox and Chrome.But it is not an integral part of the JavaScript standard ES3 or ES5. Suggestion: Don't use it