Getting started with JavaScriptFunctionsArraysObjectsAJAXClassesArithmetic (Math)Comparison OperationsConditionsLoopsPromisesRegular expressionsDateError HandlingGeolocationCookiesIntervals and TimeoutsGeneratorsHistoryStrict modeCustom ElementsJSONBinary DataTemplate LiteralsWeb StorageFetchScopeModulesScreenInheritanceTimestampsDestructuring assignmentWorkersVariable coercion/conversionDebuggingNotifications APIBuilt-in ConstantsWebSocketsWeb Cryptography APIAsync functions (async/await)StringsConstructor functionsexecCommand and contenteditablePerformance TipsMapCreational Design PatternsrequestAnimationFrameReserved KeywordsMethod ChainingGlobal error handling in browsersUnary OperatorsFile API, Blobs and FileReadersCommentsConsoleTail Call OptimizationDetecting browserEnumerationsSymbolsLocalizationSelection APICallbacksSetDeclarations and AssignmentsFunctional JavaScriptModals - PromptsData attributesThe Event LoopBattery Status APIData ManipulationBitwise operatorsTranspilingBOM (Browser Object Model)Unit Testing JavascriptLinters - Ensuring code qualityAutomatic Semicolon Insertion - ASIIndexedDBAnti-patternsNavigator ObjectModularization TechniquesProxySame Origin Policy & Cross-Origin CommunicationArrow Functions.postMessage() and MessageEventWeakMapWeakSetEscape SequencesBehavioral Design PatternsServer-sent eventsAsync IteratorsNamespacingEvaluating JavaScriptMemory efficiencyDate ComparisonHow to make iterator usable inside async callback functionContext (this)Setters and GettersVibration APIPrototypes, objectsDatatypes in JavascriptBitwise Operators - Real World Examples (snippets)Fluent APITilde ~Security issuesUsing javascript to get/set CSS custom variablesJavaScript VariablesEvents

Reserved Keywords

Other topics

Reserved Keywords

JavaScript has a predefined collection of reserved keywords which you cannot use as variables, labels, or function names.

ECMAScript 1

1
A — EE — RS — Z
breakexportsuper
caseextendsswitch
catchfalsethis
classfinallythrow
constfortrue
continuefunctiontry
debuggeriftypeof
defaultimportvar
deleteinvoid
donewwhile
elsenullwith
enumreturn

ECMAScript 2

Added 24 additional reserved keywords. (New additions in bold).

3E4X
A — FF — PP — Z
abstractfinalpublic
booleanfinallyreturn
breakfloatshort
byteforstatic
casefunctionsuper
catchgotoswitch
charifsynchronized
classimplementsthis
constimportthrow
continueinthrows
debuggerinstanceoftransient
defaultinttrue
deleteinterfacetry
dolongtypeof
doublenativevar
elsenewvoid
enumnullvolatile
exportpackagewhile
extendsprivatewith
falseprotected

ECMAScript 5 / 5.1

There was no change since ECMAScript 3.

ECMAScript 5 removed int, byte, char, goto, long, final, float, short, double, native, throws, boolean, abstract, volatile, transient, and synchronized; it added let and yield.

A — FF — PP — Z
breakfinallypublic
caseforreturn
catchfunctionstatic
classifsuper
constimplementsswitch
continueimportthis
debuggerinthrow
defaultinstanceoftrue
deleteinterfacetry
dolettypeof
elsenewvar
enumnullvoid
exportpackagewhile
extendsprivatewith
falseprotectedyield

implements, let, private, public, interface, package, protected, static, and yield are disallowed in strict mode only.

eval and arguments are not reserved words but they act like it in strict mode.


ECMAScript 6 / ECMAScript 2015

A — EE — RS — Z
breakexportsuper
caseextendsswitch
catchfinallythis
classforthrow
constfunctiontry
continueiftypeof
debuggerimportvar
defaultinvoid
deleteinstanceofwhile
donewwith
elsereturnyield

Future reserved keywords

The following are reserved as future keywords by the ECMAScript specification. They have no special functionality at present, but they might at some future time, so they cannot be used as identifiers.

enum

The following are only reserved when they are found in strict mode code:

implementspackagepublic
interfaceprivate`static'
letprotected

Future reserved keywords in older standards

The following are reserved as future keywords by older ECMAScript specifications (ECMAScript 1 till 3).

abstractfloatshort
booleangotosynchronized
byteinstanceofthrows
charinttransient
doublelongvolatile
finalnative

Additionally, the literals null, true, and false cannot be used as identifiers in ECMAScript.

From the Mozilla Developer Network.

Identifiers & Identifier Names

With regards to reserved words there is a small distinctions between the "Identifiers" used for the likes of variable or function names and the "Identifier Names" allowed as properties of composite data types.

For example the following will result in an illegal syntax error:

var break = true;

Uncaught SyntaxError: Unexpected token break

However the name is deemed valid as a property of an object (as of ECMAScript 5+):

var obj = {
    break: true
};
console.log(obj.break);

To quote from this answer:

From the ECMAScript® 5.1 Language Specification:

Section 7.6

Identifier Names are tokens that are interpreted according to the grammar given in the “Identifiers” section of chapter 5 of the Unicode standard, with some small modifications. An Identifier is an IdentifierName that is not a ReservedWord (see 7.6.1).

Syntax

Identifier ::
  IdentifierName but not ReservedWord

By specification, a ReservedWord is:

Section 7.6.1

A reserved word is an IdentifierName that cannot be used as an Identifier.

ReservedWord :: 
  Keyword
  FutureReservedWord
  NullLiteral
  BooleanLiteral

This includes keywords, future keywords, null, and boolean literals. The full list of keywords are in Sections 7.6.1 and literals are in Section 7.8.

The above (Section 7.6) implies that IdentifierNames can be ReservedWords, and from the specification for object initializers:

Section 11.1.5

Syntax

ObjectLiteral :
  { }
  { PropertyNameAndValueList }
  { PropertyNameAndValueList , }

Where PropertyName is, by specification:

PropertyName :
  IdentifierName
  StringLiteral
  NumericLiteral

As you can see, a PropertyName may be an IdentifierName, thus allowing ReservedWords to be PropertyNames. That conclusively tells us that, by specification, it is allowed to have ReservedWords such as class and var as PropertyNames unquoted just like string literals or numeric literals.

To read more, see Section 7.6 - Identifier Names and Identifiers.


Note: the syntax highlighter in this example has spotted the reserved word and still highlighted it. While the example is valid Javascript developers can get caught out by some compiler / transpiler, linter and minifier tools that argue otherwise.

Contributors

Topic Id: 1853

Example Ids: 6068,16733

This site is not affiliated with any of the contributors.