String.prototype.valueOf()
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
valueOf()
メソッドは、String
オブジェクトのプリミティブ値を返します。
試してみましょう
const stringObj = new String("foo");
console.log(stringObj);
// Expected output: String { "foo" }
console.log(stringObj.valueOf());
// Expected output: "foo"
構文
js
valueOf()
返値
与えられた String
オブジェクトのプリミティブ値を表す文字列です。
詳細
String
オブジェクトの valueOf()
メソッドは、String
オブジェクトの文字列型としてのプリミティブ値を返します。この値は、String.prototype.toString()
の返値と等価です。
このメソッドは通常、JavaScript によって内部的に呼ばれ、コード中で明示的に呼ばれることはありません。
例
valueOf()
メソッドの使用
js
const x = new String("Hello world");
console.log(x.valueOf()); // 'Hello world'
仕様書
Specification |
---|
ECMAScript® 2025 Language Specification # sec-string.prototype.valueof |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
valueOf |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.