> 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/contextual.md).

# contextual keyword

🚧 施工中

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

{% hint style="success" %}
[keyword](/web/js/grammar/token/keyword.md) that <mark style="color:green;">**can**</mark>/<mark style="color:red;">**cannot**</mark> be used as [identifier](/web/js/grammar/token/id.md) <mark style="color:orange;">**in some contexts**</mark>.

```javascript
// 18 contextual keywords
as async from get implements interface let of 
package private protected public set static target
await yield    // ⭐️ reserved words
```

{% endhint %}

{% hint style="info" %}

* <mark style="color:orange;">**contextually**</mark>**&#x20;**<mark style="color:yellow;">**allowed**</mark> as [identifier](/web/js/grammar/token/id.md)： (2)
  * <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:blue;">`yield`</mark> -&#x20;
* <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)：(8)
  * [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>：(8)
  * `as`, `from`, `get`, `meta`, `of`, `set`, `target`.&#x20;
  * [async](/web/js/async/async.md) -  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 %}

{% tabs %}
{% tab title="⭐️ 重點" %}
{% hint style="danger" %} <mark style="color:blue;">await</mark>, <mark style="color:blue;">yield</mark> are [reserved word](/web/js/grammar/token/keyword/reserved.md) and <mark style="color:purple;">**contextual keywords**</mark> at the same time.
{% endhint %}

{% hint style="warning" %}

* `NaN`, `Infinity`, and `undefined` are：
  * <mark style="color:red;">**not**</mark> <mark style="color:purple;">**reserved keywords**</mark>.
  * <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).
* JavaScript <mark style="color:red;">**does not throw**</mark> any errors if you declare them in the [global scope](https://www.tektutorialshub.com/javascript/scope-in-javascript/).

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

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

* replit：[reserved words](https://replit.com/@pegasusroe/reserved-words#index.js)

```javascript
// 18 contextual keywords
as async from get implements interface let of 
package private protected public set static target
await yield    // ⭐️ reserved words
```

{% 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) ⟩ [reserved words](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#reserved_words)
* [ ] [SyntaxError: "x" is a reserved identifier](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Reserved_identifier)
* [ ] ECMA spec ⟩ [12.6.2 Keywords and Reserved Words](https://262.ecma-international.org/13.0/#sec-keywords-and-reserved-words) ⟩ [Reserved Words](https://262.ecma-international.org/13.0/#prod-ReservedWord) ⭐️
  {% endtab %}

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

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

{% tab title="🚧" %}

* [ ] undefined
* [ ] NaN
* [ ] Infinity
  {% endtab %}
  {% endtabs %}
