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

# identifier

the name of a variable/function/property/label/parameter.

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

{% hint style="success" %}
([token](/web/js/grammar/token.md)) \
the <mark style="color:yellow;">**name**</mark> of a [variable](/web/js/variable.md) / [function](/web/js/val/func.md) / [property](/web/js/val/obj/prop.md) / [label](/web/js/grammar/statement/other/label.md) / [parameter](/web/js/val/func/param.md).

* <mark style="color:red;">**case-sensitive**</mark> :exclamation:
* <mark style="color:red;">**must**</mark>**&#x20;**<mark style="color:yellow;">**begin with**</mark>&#x20;
  * <mark style="color:orange;">**letter**</mark> (<mark style="color:blue;">`a...z, A...Z`</mark>, or [Unicode](https://developer.mozilla.org/en-US/docs/Glossary/Unicode) letter&#x73;**)**
  * <mark style="color:orange;">**underscore**</mark> (<mark style="color:blue;">`_`</mark>)
  * <mark style="color:orange;">**dollar sign**</mark> (<mark style="color:blue;">`$`</mark>)&#x20;
  * <mark style="color:red;">**may not**</mark> start with a <mark style="color:yellow;">**digit**</mark> (<mark style="color:blue;">`0-9`</mark>):exclamation:
* <mark style="color:yellow;">**subsequent**</mark>**&#x20;characters** can be <mark style="color:orange;">**digits**</mark> (<mark style="color:blue;">`0...9`</mark>).
  {% endhint %}

{% tabs %}
{% tab title="⭐️ 重點" %}
{% hint style="info" %} <mark style="color:purple;">**identifiers**</mark> &#x20;

* <mark style="color:yellow;">**registered**</mark> to respective [scope](/web/js/scope.md) at [compile-time](/web/js/compile/compile-time.md).
* <mark style="color:yellow;">**created**</mark> at the <mark style="color:yellow;">**beginning**</mark> of the [scope](/web/js/scope.md) it belongs to, <mark style="color:yellow;">**every time**</mark> that <mark style="color:yellow;">**scope**</mark> is <mark style="color:yellow;">**entered**</mark> (at [runtime](/web/js/compile/runtime.md)).
  {% 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):exclamation:\
(at least for [variable](/web/js/variable.md)/[function](/web/js/val/func.md)/[label](/web/js/grammar/statement/other/label.md))&#x20;
{% endhint %}

{% hint style="success" %}
the [property name](/web/js/val/obj/prop/name.md) in [dot notation (.)](/web/js/val/obj/prop/access/dot-notation-..md) <mark style="color:green;">**can**</mark>**&#x20;**<mark style="color:yellow;">**be**</mark> a [reserved word](/web/js/grammar/token/keyword/reserved.md):exclamation:
{% endhint %}

{% 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](/web/js/grammar/token/keyword.md)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](/web/js/grammar/token/keyword.md)s：
  * <mark style="color:red;">**never allowed**</mark> as <mark style="color:purple;">**identifiers**</mark>： \
    [reserved word](/web/js/grammar/token/keyword/reserved.md) (<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](/web/js/grammar/token/keyword.md)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 [identifier](/web/js/grammar/token/id.md)s in some contexts and as [keyword](/web/js/grammar/token/keyword.md)s in others. :blue\_book:[ECMA](https://262.ecma-international.org/13.0/#sec-keywords-and-reserved-words)
{% endhint %}

{% hint style="warning" %}
`NaN`/`Infinity`/ [undefined](/web/js/val/prim/undefined.md) are&#x20;

* <mark style="color:red;">**read-only**</mark> [properties](/web/js/val/obj/prop.md) ([identifier](/web/js/grammar/token/id.md)) of the [global object](/web/js/scope/global/object.md):exclamation:
* <mark style="color:red;">**not**</mark> [keyword](/web/js/grammar/token/keyword.md)s.
  {% endhint %}

{% hint style="info" %}
the [identifier](/web/js/grammar/token/id.md) of a [function expression](/web/js/val/func/expr.md) is in <mark style="color:yellow;">**its own**</mark> [function name scope](/web/js/scope/implied.md).&#x20;
{% endhint %}

{% hint style="success" %} <mark style="color:red;">**only**</mark> object's <mark style="color:red;">**configurable**</mark> <mark style="color:yellow;">**properties**</mark> are "<mark style="color:green;">**qualified**</mark>" for "[**delete**](/web/js/val/obj/prop/create/delete.md)", <mark style="color:yellow;">**other**</mark> <mark style="color:purple;">**identifiers**</mark> are "[**unqualified**](/web/js/val/obj/prop/create/delete/unqualified-for-delete.md)" ( <mark style="color:red;">**can't**</mark>**&#x20;**<mark style="color:yellow;">**delete them**</mark>:exclamation:). 📘 [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Delete_in_strict_mode#what_went_wrong)
{% endhint %}
{% endtab %}

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

* <mark style="color:yellow;">**types of identifiers**</mark>
  * [undeclared identifier](/web/js/grammar/token/id/undeclared.md)
  * [unqualified identifier for delete](/web/js/val/obj/prop/create/delete/unqualified-for-delete.md) - can't be deleted:exclamation:
  * [globalThis](/web/js/scope/global/object/this.md) - identifier for the [global object](/web/js/scope/global/object.md).
  * [special identifier](/web/js/grammar/token/id/special.md)
  * [label](/web/js/grammar/statement/other/label.md) of a statement
  * [function name](/web/js/val/func/name.md)
  * [parameter](/web/js/val/func/param.md)(s) of a function
  * [property name](/web/js/val/obj/prop/name.md)
* <mark style="color:yellow;">**comparisons**</mark>
  * [identifier vs. string](/web/js/grammar/token/id/vs-string.md)
  * [identifier vs. keyword](/web/js/grammar/token/id/vs-keyword.md)
* <mark style="color:yellow;">**binding of a value**</mark>
  * [static binding](/web/js/grammar/token/id/static-binding.md)\
    (the [value](/web/js/val.md) of an [identifier](/web/js/grammar/token/id.md) is <mark style="color:yellow;">**predetermined**</mark> at [compile-time](/web/js/compile/compile-time.md))
  * [dynamic binding](/web/js/grammar/token/id/dynamic-binding.md)\
    (the [value](/web/js/val.md) of an [identifier](/web/js/grammar/token/id.md) is <mark style="color:red;">**not determined**</mark> until [runtime](/web/js/compile/runtime.md))
    {% endtab %}

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

* part of [grammar](/web/js/grammar.md)
* the [identifier](/web/js/grammar/token/id.md) of a [function expression](/web/js/val/func/expr.md) is in <mark style="color:yellow;">**its own**</mark> [function name scope](/web/js/scope/implied.md).&#x20;
* :no\_entry:[delete of an unqualified identifier in strict mode❗️](/web/js/err/syntax/delete-of-an-unqualified-identifier-in-strict-mode.md) - variables can't be deleted:exclamation:
* :no\_entry:[can't delete variable/function❗️](/web/js/variable/delete.md)
* :no\_entry: the "<mark style="color:blue;">`prop`</mark>" part of [dot notation (.)](/web/js/val/obj/prop/access/dot-notation-..md) <mark style="color:red;">**must**</mark>**&#x20;**<mark style="color:yellow;">**be**</mark> an [identifier](/web/js/grammar/token/id.md):exclamation:
  {% endtab %}

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

* [ ] [YDKJS: Scope & Closures (v.2)](/web/master/ref/book/you-dont-know-js-series-v.2/ydkjs-scope-and-closures-v.2.md) ⟩ Ch. 5 ⟩ [When Can I Use a Variable?](https://github.com/getify/You-Dont-Know-JS/blob/2nd-ed/scope-closures/ch5.md#when-can-i-use-a-variable)
  {% endtab %}

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

* [ ] [Identifier](https://developer.mozilla.org/en-US/docs/Glossary/Identifier)
* [ ] ECMA ⟩ [13. Expressions](https://262.ecma-international.org/13.0/#sec-ecmascript-language-expressions) ⟩ [13.1 Identifiers](https://262.ecma-international.org/13.0/#prod-Identifier)
* [ ] [Statements and declarations](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements) ⟩ [Others](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements#others) ⟩[ label](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/label)&#x20;
  {% endtab %}
  {% endtabs %}
