CodesCompiler
πŸ”
HTMLCSSJavaScriptPythonSQLPHPSEOPostsBooksKids About Contact πŸš€ Get Started Free

JavaScript - Reserved Keywords

JavaScript - Reserved Keywords

Reserved Keywords in JavaScript

Thereserved keywordsin JavaScript are predefined keywords used to serve the built-in functionality of the programming language. For example, thevarandletkeywords are used to define variables, thefunctionkeyword 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.

JAVASCRIPT CODE
var function = "Hello";

Reserved Keywords

Here is the list of reserved keywords; you cant use them as an identifier βˆ’

abstractdoubleimplementsreturnargumentselseinswitchawaitenuminstanceofsynchronizedbooleanevalintthisbreakexportinterfacethrowbyteextendsletthrowscasefalselongtransientcatchfinalnativetruecharfinallynewtryclassfloatnulltypeofconstforpackagevarcontinuefunctionprivatevoiddebuggergotoprotectedvolatiledefaultifpublicyielddeleteimplementsshortwhiledoimportstaticwithdoubleinsuper

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.

awaitclassenumexportextendsimportletSuper

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.

abstractbooleanbytechardoublefinalfloatgotointlongnativeshortsynchronizedthrowstransientvolatile

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

ArrayArrayBufferBooleanDataViewDateErrorevalFloat32ArrayFloat64ArrayFunctionGeneratorGeneratorFunctionInt8ArrayInt16ArrayInt32ArrayIntlJSONMapMathNumberObjectPromiseProxyRangeErrorReferenceErrorReflectRegExpSetStringSymbolSyntaxErrorTypeErrorUint8ArrayUint8ClampedArrayUint16ArrayUint32ArrayURIErrorWeakMapWeakSet

JavaScript Built-in Properties

lengthconstructorprototype__proto__callercallee

JavaScript Methods

toStringshiftindexOfsplittoLocaleStringunshiftlastIndexOfsubstrvalueOfsliceincludessubstringtoLocaleDateStringspliceisArraytoLowerCasetoLocaleTimeStringsortfromtoLocaleLowerCasetoLocaleStringforEachoftoUpperCasetoFixedmapcharAttoLocaleUpperCasetoExponentialfiltercharCodeAttrimtoPrecisionreducecodePointAtstartsWithconcatreduceRightnormalizeendsWithjoineveryrepeatmatchpopsomereplacetestpushfindsearchreversefindIndexslice

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.

alertelementsframeRateradioallembedhiddenresetanchorembedshistoryscreenXanchorsencodeURIimagescreenYareaencodeURIComponentimagesscrollassignescapeoffscreenBufferingsecureblureventopenselectbuttonfileUploadopenerselfcheckboxfocusoptionsetIntervalclearIntervalformouterHeightsetTimeoutclearTimeoutformsouterWidthstatusclientInformationframepackagessubmitcloseinnerHeightpageXOffsettaintclosedinnerWidthpageYOffsettextconfirmlayerparenttextareaconstructorlayersparseFloattopcryptolinkparseIntunescapedecodeURIlocationpassworduntaintdecodeURIComponentmimeTypespkcs11windowdefaultStatusnavigateplugindocumentnavigatorpromptelementframespropertyIsEnum

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.

onclickondblclickonmouseoveronmouseoutonmousemoveonkeydownonkeyuponkeypressonfocusonbluronchangeonsubmitonresetonloadonunloadonresizeonscroll

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