> For the complete documentation index, see [llms.txt](https://lochiwei.gitbook.io/web/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lochiwei.gitbook.io/web/js/grammar/token/keyword.md).

# keyword

[JS](/web/js.md) ⟩ [grammar](/web/js/grammar.md) ⟩ [token](/web/js/grammar/token.md) ⟩ keyword

{% hint style="success" %}
A <mark style="color:purple;">**keyword**</mark> is a [token](/web/js/grammar/token.md) that matches [IdentifierName](https://262.ecma-international.org/13.0/#prod-IdentifierName) (looks like an [identifier](/web/js/grammar/token/id.md)), but also has a <mark style="color:yellow;">**syntactic use**</mark>. (:blue\_book:[ECMA](https://262.ecma-international.org/13.0/#sec-keywords-and-reserved-words) )

```javascript
// 54 keywords
as async await break case catch class const continue 
debugger default delete do else enum export extends 
false finally for from function get 
if implements import in instanceof interface 
let meta new null of package private protected public return 
set static super switch target this throw true try typeof 
var void while with yield
```

{% endhint %}

{% tabs %}
{% tab title="⭐️ 重點" %}
{% hint style="success" %} <mark style="color:purple;">**keywords**</mark> can be divided into：

* [reserved word](/web/js/grammar/token/keyword/reserved.md)： \ <mark style="color:red;">**never allowed**</mark> as [identifier](/web/js/grammar/token/id.md) (<mark style="color:orange;">**except**</mark> <mark style="color:blue;">`await`</mark>, <mark style="color:blue;">`yield`</mark>)
* [contextual keyword](/web/js/grammar/token/keyword/contextual.md)：
  * <mark style="color:orange;">**contextually**</mark>**&#x20;**<mark style="color:yellow;">**allowed**</mark> as [identifier](/web/js/grammar/token/id.md)： \
    namely <mark style="color:blue;">`await`</mark>, <mark style="color:blue;">`yield`</mark>.
    * <mark style="color:blue;">`await`</mark> -  reserved only inside [async function](/web/js/async/async/functions.md)s and [module](/web/js/module.md)s.
  * <mark style="color:orange;">**contextually**</mark> <mark style="color:red;">**disallowed**</mark> as [identifier](/web/js/grammar/token/id.md), in [strict mode code](https://262.ecma-international.org/13.0/#sec-strict-mode-code):：\
    [let](/web/js/variable/declare/let.md), `static`, `implements`, `interface`, `package`, `private`, `protected`, `public`.
  * <mark style="color:yellow;">**mostly allowed**</mark> as [identifier](/web/js/grammar/token/id.md), but <mark style="color:orange;">**also appear as**</mark> [keyword](/web/js/grammar/token/keyword.md)s <mark style="color:orange;">**within certain syntactic productions**</mark>, at places where [identifier](/web/js/grammar/token/id.md) is <mark style="color:red;">**not allowed**</mark>: \
    `as`, `async`, `from`, `get`, `meta`, `of`, `set`, `target`.
    * <mark style="color:blue;">`async`</mark> -  can be used as a [variable](/web/js/variable.md) <mark style="color:yellow;">**name**</mark> or [statement](/web/js/grammar/statement.md) <mark style="color:yellow;">**label**</mark> without restriction.
      {% endhint %}

{% hint style="warning" %}
`NaN`/`Infinity`/ [undefined](/web/js/val/prim/undefined.md) is：

* <mark style="color:red;">**not**</mark> [keyword](/web/js/grammar/token/keyword.md).
* <mark style="color:yellow;">**immutable**</mark> & <mark style="color:yellow;">**read-only**</mark> [properties](/web/js/val/obj/prop.md) of the [global object](/web/js/scope/global/object.md).
* JS <mark style="color:red;">**doesn't throw**</mark> any errors if you declare them in the [global scope](/web/js/scope/global.md).

:green\_book:[TeckTutorialHub](https://www.tektutorialshub.com/javascript/javascript-keywords-reserved-words/)
{% endhint %}

{% hint style="danger" %}

* <mark style="color:red;">**avoid**</mark> using [reserved word](/web/js/grammar/token/keyword/reserved.md) as [identifier](/web/js/grammar/token/id.md)s (at least for [variable](/web/js/variable.md)/[function](/web/js/val/func.md)) :exclamation:
* in [dot notation (.)](/web/js/val/obj/prop/access/dot-notation-..md), it's <mark style="color:yellow;">**OK**</mark> to use [reserved word](/web/js/grammar/token/keyword/reserved.md) as [property name](/web/js/val/obj/prop/name.md):exclamation:
  {% endhint %}
  {% endtab %}

{% tab title="💈範例" %}

* replit：[reserved words](https://replit.com/@pegasusroe/reserved-words#index.js)
* require： [str.replaceWhitespaces()](/web/js/val/prim/str/method/str.replacewhitespaces.md), [arr.removeDuplicates()](/web/js/val/builtin/arr/ext/arr.removeduplicates.md)

```javascript
// 54 keywords
as async await break case catch class const continue 
debugger default delete do else enum export extends 
false finally for from function get 
if implements import in instanceof interface 
let meta new null of package private protected public return 
set static super switch target this throw true try typeof 
var void while with yield
```

{% endtab %}

{% tab title="🔴 主題" %}

* [identifier vs. keyword](/web/js/grammar/token/id/vs-keyword.md)
* <mark style="color:yellow;">**types of keywords**</mark>
  * [reserved word](/web/js/grammar/token/keyword/reserved.md)
  * [contextual keyword](/web/js/grammar/token/keyword/contextual.md)
    {% endtab %}

{% tab title="📘 手冊" %}

* [Lexical grammar](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar) ⟩ [keywords](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#keywords)
* ECMA ⟩ [12.6.2 Keywords and Reserved Words](https://262.ecma-international.org/13.0/#sec-keywords-and-reserved-words) ⭐️
  {% endtab %}

{% tab title="👥 相關" %}

* part of JavaScript's [grammar](/web/js/grammar.md).
* [str.isKeyword](/web/js/val/prim/str/ext/iskeyword.md) - check if string is a keyword.
  {% endtab %}

{% tab title="📗 參考" %}

* [ ] TeckTutorialHub ⟩ [JavaScript Keywords & Reserved Words](https://www.tektutorialshub.com/javascript/javascript-keywords-reserved-words/) ⭐️
  {% endtab %}

{% tab title="🚧" %}

* [ ] undefined
* [ ] NaN
* [ ] Infinity
* [ ] variable name
* [ ] statement label
* [x] tokens
  {% endtab %}
  {% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://lochiwei.gitbook.io/web/js/grammar/token/keyword.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
