String.prototype.toUpperCase()
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.
toUpperCase()
メソッドは、呼び出す文字列の値を(文字列でない場合、文字列に変換して)大文字に変換して返します。
試してみましょう
const sentence = "The quick brown fox jumps over the lazy dog.";
console.log(sentence.toUpperCase());
// Expected output: "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG."
構文
js
toUpperCase()
返値
呼び出す文字列の値を大文字に変換した新しい文字列です。
解説
toUpperCase()
メソッドは、大文字に変換された文字列の値を返します。このメソッドは、文字列自身の値に影響を与えません(JavaScript の文字列は不変です)。
例
基本的な使用
js
console.log("alphabet".toUpperCase()); // 'ALPHABET'
文字列でない this
値を文字列に変換する
このメソッドは this
に文字列でない値を設定した場合、文字列に変換します。
js
const a = String.prototype.toUpperCase.call({
toString() {
return "abcdef";
},
});
const b = String.prototype.toUpperCase.call(true);
// 'ABCDEF TRUE' と表示
console.log(a, b);
仕様書
Specification |
---|
ECMAScript® 2025 Language Specification # sec-string.prototype.touppercase |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
toUpperCase |
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.