# .toString()

[JS](https://lochiwei.gitbook.io/web/js) ⟩ [value](https://lochiwei.gitbook.io/web/js/val) ⟩ [type](https://lochiwei.gitbook.io/web/js/val/type) ⟩ [conversion](https://lochiwei.gitbook.io/web/js/val/type/convert) ⟩ .toString()

{% hint style="success" %} <mark style="color:red;">**object**</mark>**&#x20;**<mark style="color:yellow;">**to string**</mark>**&#x20;conversion**<mark style="color:yellow;">**.**</mark>
{% endhint %}

{% tabs %}
{% tab title="⭐️ 重點" %}
{% hint style="info" %} <mark style="color:red;">**any**</mark> [<mark style="color:yellow;">**non-nullish**</mark>](https://lochiwei.gitbook.io/web/js/val/prim/nullish) value has [**.toString()**](https://lochiwei.gitbook.io/web/js/val/obj/convert/.tostring) method, usually equivalent to [<mark style="color:blue;">**String**</mark>](https://lochiwei.gitbook.io/web/js/val/prim/str)**().**
{% endhint %}

{% hint style="warning" %}
[Console](https://github.com/whatwg/console) API (<mark style="color:yellow;">`console.log`</mark>, for example) is <mark style="color:red;">**not**</mark>**&#x20;**<mark style="color:yellow;">**(yet) a standard API**</mark>, but is something that is implemented across all browsers, implementations may differ, <mark style="color:purple;">**toString**</mark> <mark style="color:yellow;">**may or may**</mark>**&#x20;**<mark style="color:red;">**not**</mark> be used in these implementations. :point\_right: [stackoverflow](https://stackoverflow.com/a/36216072/5409815)
{% endhint %}
{% endtab %}

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

* [convert](https://lochiwei.gitbook.io/web/js/val/type/convert "mention")
  {% endtab %}

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

* [ ] [javascript-the-definitive-guide](https://lochiwei.gitbook.io/web/master/ref/javascript-the-definitive-guide "mention") ⟩&#x20;
  * [ ] 3.9.2 Explicit Conversions
  * [ ] 14.4.7
* [ ] [WHATWG](https://whatwg.org/) ⟩ [Console](https://github.com/whatwg/console) Standard\
  (Web Hypertext Application Technology Working Group)
  {% endtab %}

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

* [Object.prototype.toString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString) - object to string.
* [Object.prototype.valueOf()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf) - object to (primitive) value, if exists.
  {% endtab %}

{% tab title="🗣 討論" %}

* [Does console.log invokes toString method of an object?](https://stackoverflow.com/a/36216072/5409815)
  {% endtab %}

{% tab title="🚧" %}

* [ ] merge with [valuetostring](https://lochiwei.gitbook.io/web/js/val/obj/convert/valuetostring "mention")
  {% endtab %}
  {% endtabs %}
