JavaScript Reserved Keywords

Site: Saylor Academy
Course: PRDV401: Introduction to JavaScript I
Book: JavaScript Reserved Keywords
Printed by: Guest user
Date: Sunday, May 19, 2024, 1:02 AM

Description

JavaScript statements begin with a "reserved keyword" and perform a specific task. For example, the "var" keyword instructs the browser to create a variable. This article provides a list of the keywords used in JavaScript. It is important to remember that a "variable" or "function" cannot use keywords. This is another interactive reference to use as you learn to write JavaScript statements.

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.  

These are always reserved:

  • enum

The following are only reserved when they are found in strict mode code or async function bodies::

  • implements
  • interface
  • let
  • package
  • private
  • protected
  • public
  • static
  • yield

The following are only reserved when they are found in module code:

  • await

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

  • let

Future reserved keywords in older standards

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

  • abstract
  • boolean
  • byte
  • char
  • double
  • final
  • float
  • goto
  • int
  • long
  • native
  • short
  • synchronized
  • throws
  • transient
  • volatile

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

Reserved word usage

Reserved words actually only apply to Identifiers (vs. IdentifierNames) . As described in es5.github.com/#A.1, these are all IdentifierNames which do not exclude ReservedWords.

a.import
a['import']
a = { import: 'test' }.

On the other hand the following is illegal because it's an Identifier, which is an IdentifierName without the reserved words. Identifiers are used for FunctionDeclaration, FunctionExpression, VariableDeclaration and so on. IdentifierNames are used for MemberExpression,CallExpression and so on.

function import() {} // Illegal.

Identifiers with special meanings

A few identifiers have a special meaning in some contexts without being keywords of any kind. They include:

  • arguments
  • get
  • set