JavaScript – Reserved Keywords

Reserved Keywords in JavaScript

The reserved keywords in JavaScript are predefined keywords used to serve the built-in functionality of the programming language. For example, the var and let keywords are used to define variables, the function keyword is used to define the functions, etc. JavaScript contains more that fifty reserved keywords.

In simple terms, you can’t use the reserved keywords as an identifier. If you do, you will get the conflicts, and the code will generate the wrong output or throw an error.

For example, the below code will throw an error as function is used as an identifier.

varfunction="Hello";

Reserved Keywords

Here is the list of reserved keywords; you cant use them as an identifier −

abstractdoubleimplementsreturn
argumentselseinswitch
awaitenuminstanceofsynchronized
booleanevalintthis
breakexportinterfacethrow
byteextendsletthrows
casefalselongtransient
catchfinalnativetrue
charfinallynewtry
classfloatnulltypeof
constforpackagevar
continuefunctionprivatevoid
debuggergotoprotectedvolatile
defaultifpublicyield
deleteimplementsshortwhile
doimportstaticwith
doubleinsuper

Reserved Keywords added in ES5 and ES6

Some new keywords are added in the ES5 and ES6 versions of JavaScript. However, some are currently in use, and some keywords are reserved for future versions.

awaitclassenumexport
extendsimportletSuper

Removed Reserved Keywords

Some reserved keywords are removed from JavaScript, which you cant use to achieve a particular functionality. Still, you cant use the keywords below as an identifier as many browsers dont support them.

abstractbooleanbytechar
doublefinalfloatgoto
intlongnativeshort
synchronizedthrowstransientvolatile

JavaScript Objects, Properties, and Methods

You should not use the name of JavaScript built-in objects, properties, and methods names as an identifier.

JavaScript Built-in Objects

ArrayArrayBufferBooleanDataView
DateErrorevalFloat32Array
Float64ArrayFunctionGeneratorGeneratorFunction
Int8ArrayInt16ArrayInt32ArrayIntl
JSONMapMathNumber
ObjectPromiseProxyRangeError
ReferenceErrorReflectRegExpSet
StringSymbolSyntaxErrorTypeError
Uint8ArrayUint8ClampedArrayUint16ArrayUint32Array
URIErrorWeakMapWeakSet

JavaScript Built-in Properties

lengthconstructorprototype__proto__callercallee

JavaScript Methods

toStringshiftindexOfsplit
toLocaleStringunshiftlastIndexOfsubstr
valueOfsliceincludessubstring
toLocaleDateStringspliceisArraytoLowerCase
toLocaleTimeStringsortfromtoLocaleLowerCase
toLocaleStringforEachoftoUpperCase
toFixedmapcharAttoLocaleUpperCase
toExponentialfiltercharCodeAttrim
toPrecisionreducecodePointAtstartsWith
concatreduceRightnormalizeendsWith
joineveryrepeatmatch
popsomereplacetest
pushfindsearchreverse
findIndexslice

However, you can explore more built-in JavaScript methods and avoid using them as an identifier.

Other Reserved Keywords

JavaScript can be used with other programming languages like HTML, Java, etc. So, you should also avoid keywords that are reserved in HTML, Java, etc.

Here is the list of other reserved keywords, and most of them are properties of the window object.

alertelementsframeRateradio
allembedhiddenreset
anchorembedshistoryscreenX
anchorsencodeURIimagescreenY
areaencodeURIComponentimagesscroll
assignescapeoffscreenBufferingsecure
blureventopenselect
buttonfileUploadopenerself
checkboxfocusoptionsetInterval
clearIntervalformouterHeightsetTimeout
clearTimeoutformsouterWidthstatus
clientInformationframepackagessubmit
closeinnerHeightpageXOffsettaint
closedinnerWidthpageYOffsettext
confirmlayerparenttextarea
constructorlayersparseFloattop
cryptolinkparseIntunescape
decodeURIlocationpassworduntaint
decodeURIComponentmimeTypespkcs11window
defaultStatusnavigateplugindocument
navigatorpromptelementframes
propertyIsEnum

HTML Event Handlers

You shouldnt use the HTML even handlers as a variable name in JavaScript.

Here, we have listed some of the event handlers.

onclickondblclickonmouseoveronmouseout
onmousemoveonkeydownonkeyuponkeypress
onfocusonbluronchangeonsubmit
onresetonloadonunloadonresize
onscroll

In short, you should avoid using all the above keywords as a variable or function name.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *