---
description: 🚧 施工中
---

# keyword

[JS](../..) ⟩ [grammar](..) ⟩ [token]() ⟩ keyword

{% hint style="success" %}
A <mark style="color:purple;">**keyword**</mark> is a [](<> "mention") that matches [IdentifierName](https://262.ecma-international.org/13.0/#prod-IdentifierName) (looks like an [id](id "mention")), 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](keyword/reserved "mention")： \
  <mark style="color:red;">**never allowed**</mark> as [id](id "mention") (<mark style="color:orange;">**except**</mark> <mark style="color:blue;">`await`</mark>, <mark style="color:blue;">`yield`</mark>)
* [contextual](keyword/contextual "mention")：
  * <mark style="color:orange;">**contextually**</mark>**&#x20;**<mark style="color:yellow;">**allowed**</mark> as [id](id "mention")： \
    namely <mark style="color:blue;">`await`</mark>, <mark style="color:blue;">`yield`</mark>.
    * <mark style="color:blue;">`await`</mark> -  reserved only inside [functions](../../async/async/functions "mention")s and [module](../../module "mention")s.
  * <mark style="color:orange;">**contextually**</mark> <mark style="color:red;">**disallowed**</mark> as [id](id "mention"), in [strict mode code](https://262.ecma-international.org/13.0/#sec-strict-mode-code):：\
    [let](../../variable/declare/let "mention"), `static`, `implements`, `interface`, `package`, `private`, `protected`, `public`.
  * <mark style="color:yellow;">**mostly allowed**</mark> as [id](id "mention"), but <mark style="color:orange;">**also appear as**</mark> [keyword](keyword "mention")s <mark style="color:orange;">**within certain syntactic productions**</mark>, at places where [id](id "mention") 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](../../variable "mention") <mark style="color:yellow;">**name**</mark> or [statement](../statement "mention") <mark style="color:yellow;">**label**</mark> without restriction.
{% endhint %}

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

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

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

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

{% tab title="💈範例" %}
* replit：[reserved words](https://replit.com/@pegasusroe/reserved-words#index.js)
* require： [str.replacewhitespaces](../../val/prim/str/method/str.replacewhitespaces "mention"), [arr.removeduplicates](../../val/builtin/arr/ext/arr.removeduplicates "mention")

```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="🔴 主題" %}
* [vs-keyword](id/vs-keyword "mention")
* <mark style="color:yellow;">**types of keywords**</mark>
  * [reserved](keyword/reserved "mention")
  * [contextual](keyword/contextual "mention")
{% 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 [..](.. "mention").
* [iskeyword](../../val/prim/str/ext/iskeyword "mention") - 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 %}
