blob: 303a29bcd6e608ede09a89ccacf352beb032969f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
---
title: String.prototype.toUpperCase()
slug: Web/JavaScript/Reference/Global_Objects/String/toUpperCase
tags:
- JavaScript
- Method
- Prototype
- Reference
- String
- メソッド
translation_of: Web/JavaScript/Reference/Global_Objects/String/toUpperCase
---
<div>{{JSRef}}</div>
<p><strong><code>toUpperCase()</code></strong> メソッドは、呼び出す文字列の値を(文字列でない場合、文字列に変換して)大文字に変換して返します。</p>
<div>{{EmbedInteractiveExample("pages/js/string-touppercase.html","shorter")}}</div>
<div class="hidden">このデモのソースファイルは GitHub リポジトリに格納されています。デモプロジェクトに協力したい場合は、 <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> をクローンしてプルリクエストを送信してください。</div>
<h2 id="Syntax" name="Syntax">構文</h2>
<pre class="syntaxbox"><var>str</var>.toUpperCase()</pre>
<h3 id="Return_value" name="Return_value">戻り値</h3>
<p>呼び出す文字列の値を大文字に変換した新しい文字列です。</p>
<h3 id="Exceptions" name="Exceptions">例外</h3>
<dl>
<dt>{{jsxref("TypeError")}}</dt>
<dd>{{jsxref("null")}} か {{jsxref("undefined")}} で呼ばれた場合(例えば、<code>String.prototype.toUpperCase.call(undefined)</code>)。</dd>
</dl>
<h2 id="Description" name="Description">詳細</h2>
<p><code>toUpperCase()</code> メソッドは、大文字に変換された文字列の値を返します。このメソッドは、文字列自身の値に影響を与えません(JavaScript の文字列は不変です)。</p>
<h2 id="Examples" name="Examples">例</h2>
<h3 id="Basic_usage" name="Basic_usage">基本的な使用</h3>
<pre class="brush: js">console.log('alphabet'.toUpperCase()); // 'ALPHABET'
</pre>
<h3 id="Conversion_of_non-string_this_values_to_strings" name="Conversion_of_non-string_this_values_to_strings">文字列でない <code>this</code> 値を文字列に変換する</h3>
<p>このメソッドは <code>this</code> に文字列でない値を設定した場合、文字列に変換します。:</p>
<pre class="brush: js">const a = String.prototype.toUpperCase.call({
toString: function toString() {
return 'abcdef';
}
});
const b = String.prototype.toUpperCase.call(true);
// prints out 'ABCDEF TRUE'.
console.log(a, b);
</pre>
<h2 id="Specifications" name="Specifications">仕様書</h2>
<table class="standard-table">
<thead>
<tr>
<th scope="col">仕様書</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{SpecName('ESDraft', '#sec-string.prototype.touppercase', 'String.prototype.toUpperCase')}}</td>
</tr>
</tbody>
</table>
<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2>
<p>{{Compat("javascript.builtins.String.toUpperCase")}}</p>
<h2 id="See_also" name="See_also">関連情報</h2>
<ul>
<li>{{jsxref("String.prototype.toLocaleLowerCase()")}}</li>
<li>{{jsxref("String.prototype.toLocaleUpperCase()")}}</li>
<li>{{jsxref("String.prototype.toLowerCase()")}}</li>
</ul>
|