# identifier vs. keyword

[JS](https://lochiwei.gitbook.io/web/js) ⟩ [identifier](https://lochiwei.gitbook.io/web/js/grammar/token/id) ⟩ vs. keyword

{% hint style="success" %}
there are <mark style="color:yellow;">**5 categories**</mark> of <mark style="color:purple;">**identifier**</mark> names:

* <mark style="color:red;">**not**</mark> [keyword](https://lochiwei.gitbook.io/web/js/grammar/token/keyword "mention")s (<mark style="color:green;">**always**</mark>**&#x20;**<mark style="color:yellow;">**allowed**</mark> as <mark style="color:purple;">**identifiers**</mark>)： \ <mark style="color:blue;">`Math`</mark>, <mark style="color:blue;">`window`</mark>, <mark style="color:blue;">`toString`</mark>, <mark style="color:blue;">`_`</mark> ...
* [keyword](https://lochiwei.gitbook.io/web/js/grammar/token/keyword "mention")s：
  * <mark style="color:red;">**never allowed**</mark> as <mark style="color:purple;">**identifiers**</mark>： \
    [reserved](https://lochiwei.gitbook.io/web/js/grammar/token/keyword/reserved "mention") (<mark style="color:orange;">**except**</mark> <mark style="color:blue;">`await`</mark>, <mark style="color:blue;">`yield`</mark>)
  * <mark style="color:orange;">**contextually**</mark>**&#x20;**<mark style="color:yellow;">**allowed**</mark> as <mark style="color:purple;">**identifiers**</mark>： \
    namely <mark style="color:blue;">`await`</mark>, <mark style="color:blue;">`yield`</mark>.
  * <mark style="color:orange;">**contextually**</mark> <mark style="color:red;">**disallowed**</mark> as <mark style="color:purple;">**identifiers**</mark>, in [strict mode code](https://262.ecma-international.org/13.0/#sec-strict-mode-code):：\
    `let`, `static`, `implements`, `interface`, `package`, `private`, `protected`, `public`.
  * <mark style="color:yellow;">**always allowed**</mark> as <mark style="color:purple;">**identifiers**</mark>, but <mark style="color:orange;">**also appear as**</mark> [keyword](https://lochiwei.gitbook.io/web/js/grammar/token/keyword "mention")s <mark style="color:orange;">**within certain syntactic productions**</mark>, at places where <mark style="color:purple;">**identifier**</mark> is <mark style="color:red;">**not allowed**</mark>: \
    `as`, `async`, `from`, `get`, `meta`, `of`, `set`, `target`.

The term <mark style="color:yellow;">**conditional keyword**</mark>, or <mark style="color:yellow;">**contextual keyword**</mark>, is sometimes used to refer to the keywords that fall in the <mark style="color:yellow;">**last 3 categories**</mark>, and thus can be used as [](https://lochiwei.gitbook.io/web/js/grammar/token/id "mention")s in some contexts and as [keyword](https://lochiwei.gitbook.io/web/js/grammar/token/keyword "mention")s in others. :blue\_book:[ECMA](https://262.ecma-international.org/13.0/#sec-keywords-and-reserved-words)
{% endhint %}

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

* [ ] [Lexical grammar](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar) ⟩&#x20;
  * [ ] [keywords](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#keywords)
  * [ ] [Identifier](https://developer.mozilla.org/en-US/docs/Glossary/Identifier)
    {% endtab %}
    {% endtabs %}
