Reserved Words

  • Revision slug: JavaScript/Reference/Reserved_Words
  • Revision title: Reserved Words
  • Revision id: 336695
  • Created:
  • Creator: ethertank
  • Is current revision? No
  • Comment Styling, CleanUp.

Revision Content

The following are keywords and may not be used as variables, functions, methods, or object identifiers, because ECMAScript specifies special behavior for them:

Words reserved for possible future use

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 keywords may not be used in either strict or non-strict mode.

Note: Prior to Firefox 5 (JavaScript 1.8.6), these keywords could be used when not in strict mode. This ECMAScript violation was fixed in Firefox 5.

The following are reserved as future keywords by the ECMAScript specification when they are found in strict mode code, except that let and yield have their traditional Mozilla-specific functionality in code compiled as JavaScript 1.7 or greater:

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

Note that while const is reserved as a future keyword by the ECMAScript specification, Mozilla and most other browsers implement it as a non-standard extension that may be standardized in a future version of ECMAScript. Further, export and import were once implemented in Mozilla but have returned to reserved status in recent releases.

Additionally, the literals null, true, and false are reserved in ECMAScript for their normal uses.

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 and FunctionExpression.

function import() {}

Revision Source

<p>The following are keywords and may not be used as variables, functions, methods, or object identifiers, because <a href="/en-US/docs/JavaScript/Language_Resources" title="ECMAScript">ECMAScript</a> specifies special behavior for them:</p>

<div class="threecolumns">
<ul>
  <li><code><a href="/en-US/docs/JavaScript/Reference/Statements/break" title="JavaScript/Reference/Statements/break">break</a></code></li>
  <li><code><a href="/en-US/docs/JavaScript/Reference/Statements/switch" title="JavaScript/Reference/Statements/switch">case</a></code></li>
  <li><code><a href="/en-US/docs/JavaScript/Reference/Statements/try...catch" title="JavaScript/Reference/Statements/try...catch">catch</a></code></li>
  <li><code><a href="/en-US/docs/JavaScript/Reference/Statements/continue" title="JavaScript/Reference/Statements/continue">continue</a></code></li>
  <li><code><a href="/en-US/docs/JavaScript/Reference/Statements/debugger" title="JavaScript/Reference/Statements/debugger">debugger</a></code></li>
  <li><code><a href="/en-US/docs/JavaScript/Reference/Statements/switch" title="JavaScript/Reference/Statements/switch">default</a></code></li>
  <li><code><a href="/en-US/docs/JavaScript/Reference/Operators/delete" title="JavaScript/Reference/Operators/delete">delete</a></code></li>
  <li><code><a href="/en-US/docs/JavaScript/Reference/Statements/do...while" title="JavaScript/Reference/Statements/do...while">do</a></code></li>
  <li><code><a href="/en-US/docs/JavaScript/Reference/Statements/if...else" title="JavaScript/Reference/Statements/if...else">else</a></code></li>
  <li><code><a href="/en-US/docs/JavaScript/Reference/Statements/try...catch" title="JavaScript/Reference/Statements/try...catch">finally</a></code></li>
  <li><code><a href="/en-US/docs/JavaScript/Reference/Statements/for" title="JavaScript/Reference/Statements/for">for</a></code></li>
  <li><code><a href="/en-US/docs/JavaScript/Reference/Statements/function" title="JavaScript/Reference/Statements/function">function</a></code></li>
  <li><code><a href="/en-US/docs/JavaScript/Reference/Statements/if...else" title="JavaScript/Reference/Statements/if...else">if</a></code></li>
  <li><code><a href="/en-US/docs/JavaScript/Reference/Statements/for...in" title="JavaScript/Reference/Statements/for...in">in</a></code></li>
  <li><code><a href="/en-US/docs/JavaScript/Reference/Operators/instanceof" title="JavaScript/Reference/Operators/instanceof">instanceof</a></code></li>
  <li><code><a href="/en-US/docs/JavaScript/Reference/Operators/new" title="JavaScript/Reference/Operators/new">new</a></code></li>
  <li><code><a href="/en-US/docs/JavaScript/Reference/Statements/return" title="JavaScript/Reference/Statements/return">return</a></code></li>
  <li><code><a href="/en-US/docs/JavaScript/Reference/Statements/switch" title="JavaScript/Reference/Statements/switch">switch</a></code></li>
  <li><code><a href="/en-US/docs/JavaScript/Reference/Operators/this" title="JavaScript/Reference/Operators/this">this</a></code></li>
  <li><code><a href="/en-US/docs/JavaScript/Reference/Statements/throw" title="JavaScript/Reference/Statements/throw">throw</a></code></li>
  <li><code><a href="/en-US/docs/JavaScript/Reference/Statements/try...catch" title="JavaScript/Reference/Statements/try...catch">try</a></code></li>
  <li><code><a href="/en-US/docs/JavaScript/Reference/Operators/typeof" title="JavaScript/Reference/Operators/typeof">typeof</a></code></li>
  <li><code><a href="/en-US/docs/JavaScript/Reference/Statements/var" title="JavaScript/Reference/Statements/var">var</a></code></li>
  <li><code><a href="/en-US/docs/JavaScript/Reference/Operators/void" title="JavaScript/Reference/Operators/void">void</a></code></li>
  <li><code><a href="/en-US/docs/JavaScript/Reference/Statements/while" title="JavaScript/Reference/Statements/while">while</a></code></li>
  <li><code><a href="/en-US/docs/JavaScript/Reference/Statements/with" title="JavaScript/Reference/Statements/with">with</a></code></li>
</ul>
</div>
<h2 id="Words_reserved_for_possible_future_use" name="Words_reserved_for_possible_future_use">Words reserved for possible future use</h2>
<p>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 keywords may not be used in either strict or non-strict mode.</p>
<div class="note">
  <strong>Note:</strong> Prior to Firefox 5 (JavaScript 1.8.6), these keywords could be used when not in strict mode. This ECMAScript violation was fixed in Firefox 5.</div>

<div class="threecolumns">
<ul>
  <li><code>class</code></li>
  <li><code>enum</code></li>
  <li><code><a href="/en-US/docs/JavaScript/Reference/Statements/export" title="JavaScript/Reference/Statements/export">export</a></code></li>
  <li><code>extends</code></li>
  <li><code><a href="/en-US/docs/JavaScript/Reference/Statements/import" title="JavaScript/Reference/Statements/import">import</a></code></li>
  <li><code>super</code></li>
</ul>
</div>
<p>The following are reserved as future keywords by the ECMAScript specification when they are found in <a href="/en-US/docs/JavaScript/Reference/Functions_and_function_scope/Strict_mode" title="JavaScript/Strict mode">strict mode code</a>, except that <code>let</code> and <code>yield</code> have their traditional Mozilla-specific functionality in code compiled as JavaScript 1.7 or greater:</p>

<div class="threecolumns">
<ul>
  <li><code>implements</code></li>
  <li><code>interface</code></li>
  <li><code><a href="/en-US/docs/JavaScript/Reference/Statements/let" title="JavaScript/Reference/Statements/let">let</a></code></li>
  <li><code>package</code></li>
  <li><code>private</code></li>
  <li><code>protected</code></li>
  <li><code>public</code></li>
  <li><code>static</code></li>
  <li><code><a href="/en-US/docs/JavaScript/Reference/Statements/yield" title="JavaScript/Reference/Statements/yield">yield</a></code></li>
</ul>
</div>

<p>Note that while <code><a href="/en-US/docs/JavaScript/Reference/Statements/const" title="JavaScript/Reference/Statements/const">const</a></code> is reserved as a future keyword by the ECMAScript specification, Mozilla and most other browsers implement it as a non-standard extension that may be standardized in a future version of ECMAScript. Further, <a href="/en-US/docs/JavaScript/Reference/Statements/export" title="JavaScript/Reference/Statements/export">export</a> and <a href="/en-US/docs/JavaScript/Reference/Statements/import" title="JavaScript/Reference/Statements/import">import</a> were once implemented in Mozilla but have returned to reserved status in recent releases.</p>
<p>Additionally, the literals <code>null</code>, <code>true</code>, and <code>false</code> are reserved in ECMAScript for their normal uses.</p>


<h2 id="Reserved_word_usage" name="Reserved_word_usage">Reserved word usage</h2>
<p>Reserved Words actually only apply to Identifiers (vs. <span class="comment-copy">IdentifierNames) </span>. <span class="comment-copy">As described in <a href="http://es5.github.com/#A.1" rel="nofollow">es5.github.com/#A.1</a>, these are all IdentifierNames which do not exclude ReservedWords.</span></p>
<p><span class="comment-copy"><code>a.import</code></span><br />
  <span class="comment-copy"><code>a["import"]</code></span><br />
  <span class="comment-copy"><code>a = { import: "test" }</code>.</span></p>
<p><span class="comment-copy">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 and FunctionExpression.</span></p>
<p><span class="comment-copy"><code>function import() {}</code></span></p>
Revert to this revision