# Symbol

[JS](https://lochiwei.gitbook.io/web/js) ⟩ [value](https://lochiwei.gitbook.io/web/js/val) ⟩ [primitive](https://lochiwei.gitbook.io/web/js/val/prim) ⟩ symbol

{% hint style="success" %}
returns a [](https://lochiwei.gitbook.io/web/js/val/prim "mention") <mark style="color:yellow;">**value**</mark> that's guaranteed to be <mark style="color:yellow;">**unique**</mark>.

```javascript
const unique = Symbol()    // ⭐️ not `new Symbol()`❗️ 
let obj = {
    [unique]: <value>,     // symbol used as a computed property name
};
```

{% endhint %}

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

* <mark style="color:red;">**only**</mark>**&#x20;**<mark style="color:yellow;">**used as**</mark> [**(computed) property names**](https://lochiwei.gitbook.io/web/js/val/obj/prop/name/computed).:exclamation:
* are [**primitive**](https://lochiwei.gitbook.io/web/js/val/prim) values, <mark style="color:red;">**not**</mark>**&#x20;**<mark style="color:yellow;">**objects**</mark>, <mark style="color:purple;">**Symbol()**</mark> <mark style="color:yellow;">**is**</mark>**&#x20;**<mark style="color:red;">**not**</mark> a [**constructor**](https://lochiwei.gitbook.io/web/js/val/func/constructor).:exclamation:
* <mark style="color:red;">**can't**</mark>**&#x20;**<mark style="color:yellow;">**invoke with**</mark> [**new**](https://lochiwei.gitbook.io/web/js/val/obj/create/new):exclamation:
  {% endhint %}
  {% endtab %}

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

* [iterator](https://lochiwei.gitbook.io/web/js/val/prim/symbol/iterator "mention") - name of a required method for iterables.
  {% endtab %}

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

* <mark style="color:purple;">**Symbols**</mark> can be used as [**computed property names**](https://lochiwei.gitbook.io/web/js/val/obj/prop/name/computed).
* [obj](https://lochiwei.gitbook.io/web/js/val/obj/create/obj "mention")
  {% endtab %}

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

* [ ] [javascript-the-definitive-guide](https://lochiwei.gitbook.io/web/master/ref/javascript-the-definitive-guide "mention") ⟩&#x20;
  * [ ] 3.6 Symbols
  * [ ] 6.10.3 Symbols as Property Names
    {% endtab %}

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

* [Symbol](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol)
  {% endtab %}
  {% endtabs %}
