> 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/val/obj/convert/obj-to-prim/prefer-string.md).

# prefer-string

[JS](/web/js.md) ⟩ [value](/web/js/val.md) ⟩ [type](/web/js/val/type.md) ⟩ [conversion](/web/js/val/type/convert.md) ⟩ [object -> primitive](/web/js/val/obj/convert/obj-to-prim.md) ⟩ prefer-string

{% hint style="success" %}

* <mark style="color:yellow;">**prefer-**</mark><mark style="color:red;">**string**</mark>：preferring a string (if conversion is possible)
  {% endhint %}

{% tabs %}
{% tab title="🗺️ 圖表" %} <img src="https://2527454625-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfvEFZnSBhKT6fJmus0%2Fuploads%2FSrzahlasA7PWTpTjnyuU%2Fprefer.string.svg?alt=media&amp;token=724a2745-72e2-4d65-80be-7c680028413e" alt="" class="gitbook-drawing">
{% endtab %}

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

* :no\_entry: "<mark style="color:purple;">**prefer-string**</mark>" may result in [⛔️ TypeError](/web/js/err/type.md):exclamation:
  {% endtab %}

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

* [ ] [JavaScript: The Definitive Guide](/web/master/ref/javascript-the-definitive-guide.md) ⟩&#x20;
  * [ ] 3.9.2 Explicit Conversions
  * [ ] 3.9.3 Object to Primitive Conversions
  * [ ] 14.4.7
    {% 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 %}
  {% endtabs %}
