Get to know MDN better
このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015年7月.
toString() は String 値のメソッドで、指定されたオブジェクトを表す文字列を返します。
なし。
呼び出したオブジェクトを表す文字列です。
その String オブジェクトは、Object の toString メソッドを上書きします。つまり、Object.prototype.toString() を継承しません。String オブジェクトの toString メソッドは、そのオブジェクトを表す文字列を返します(String.prototype.valueOf() と同等です)。
toString() メソッドは this 値が String プリミティブまたはラッパーオブジェクトであることを要求します。他の this の値に対しては、文字列値に変換しようとせずに TypeError を発生します。
String には [Symbol.toPrimitive]() メソッドがないため、JavaScript は toString() メソッドを、文字列が求められるコンテキスト、例えばテンプレートリテラルで String オブジェクトが使用されると、自動的に呼び出します。しかし、文字列プリミティブ値は文字列に変換するために toString() を呼び出しません。既に文字列なので、変換が実施されないからです。
以下の例は、String オブジェクトを表す文字列の値を表示します。
| ECMAScript® 2027 Language Specification # sec-string.prototype.tostring |
Enable JavaScript to view this browser compatibility table.
This page was last modified on 2025年8月22日 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.