blob: aeaa8628e9a6b90f46b54fef7b4da33d36cb2d37 (
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
---
title: String.prototype.toUpperCase()
slug: Web/JavaScript/Reference/Global_Objects/String/toUpperCase
tags:
- JavaScript
- Méthode
- Prototype
- Reference
- String
translation_of: Web/JavaScript/Reference/Global_Objects/String/toUpperCase
original_slug: Web/JavaScript/Reference/Objets_globaux/String/toUpperCase
---
<div>{{JSRef}}</div>
<p>La méthode <code><strong>toUpperCase()</strong></code> retourne la valeur de la chaîne courante, convertie en majuscules.</p>
<div>{{EmbedInteractiveExample("pages/js/string-touppercase.html")}}</div>
<p class="hidden">Le code source de cet exemple interactif est disponible dans un dépôt GitHub. Si vous souhaitez contribuez à ces exemples, n'hésitez pas à cloner <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> et à envoyer une <em>pull request</em> !</p>
<h2 id="Syntaxe">Syntaxe</h2>
<pre class="syntaxbox"><var>str</var>.toUpperCase()</pre>
<h3 id="Valeur_de_retour">Valeur de retour</h3>
<p>Une nouvelle chaîne de caractères obtenue à partir de la chaîne appelante, passée en majuscules.</p>
<h3 id="Exceptions_levées">Exceptions levées</h3>
<dl>
<dt>{{jsxref("TypeError")}}</dt>
<dd>Une telle exception sera levée si on appelle cette méthode sur {{jsxref("null")}} ou {{jsxref("undefined")}} (en utilisant <code>Function.prototype.call()</code> par exemple).</dd>
</dl>
<h2 id="Description">Description</h2>
<p>La méthode <code>toUpperCase()</code> retourne la valeur de la chaîne convertie en majuscules. <code>toUpperCase</code> n'affecte pas la valeur de la chaîne elle-même.</p>
<h2 id="Exemples">Exemples</h2>
<h3 id="Utiliser_toUpperCase()">Utiliser <code>toUpperCase()</code></h3>
<pre class="brush: js">console.log( "alphabet".toUpperCase() ); // "ALPHABET"</pre>
<h3 class="brush: js" id="Convertir_une_valeur_this_en_chaîne_de_caractères">Convertir une valeur <code>this</code> en chaîne de caractères</h3>
<p class="brush: js">Cette peut être utilisée pour convertir une valeur qui n'est pas une chaîne de caractères lorsque celle-ci est fournie comme valeur <code>this</code> : </p>
<pre class="brush: js">var obj = {
toString: function toString(){
return 'abcdef';
}
};
var a = String.prototype.toUpperCase.call(obj);
var b = String.prototype.toUpperCase.call(true);
console.log(a); // Affiche 'ABCDEF' dans la console
console.log(b); // Affiche 'TRUE' dans la console
</pre>
<h2 id="Spécifications">Spécifications</h2>
<table class="standard-table">
<thead>
<tr>
<th scope="col">Spécification</th>
<th scope="col">État</th>
<th scope="col">Commentaires</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{SpecName('ES1')}}</td>
<td>{{Spec2('ES1')}}</td>
<td>Définition initiale. Implémentée avec JavaScript 1.0.</td>
</tr>
<tr>
<td>{{SpecName('ES5.1', '#sec-15.5.4.18', 'String.prototype.toUpperCase')}}</td>
<td>{{Spec2('ES5.1')}}</td>
<td> </td>
</tr>
<tr>
<td>{{SpecName('ES6', '#sec-string.prototype.touppercase', 'String.prototype.toUpperCase')}}</td>
<td>{{Spec2('ES6')}}</td>
<td> </td>
</tr>
<tr>
<td>{{SpecName('ESDraft', '#sec-string.prototype.touppercase', 'String.prototype.toUpperCase')}}</td>
<td>{{Spec2('ESDraft')}}</td>
<td> </td>
</tr>
</tbody>
</table>
<h2 id="Compatibilité_des_navigateurs">Compatibilité des navigateurs</h2>
<p class="hidden">Le tableau de compatibilité de cette page a été généré à partir de données structurées. Si vous souhaitez contribuer à ces données, n'hésitez pas à envoyer une <em>pull request</em> sur <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a>.</p>
<p>{{Compat("javascript.builtins.String.toUpperCase")}}</p>
<h2 id="Voir_aussi">Voir aussi</h2>
<ul>
<li>{{jsxref("String.prototype.toLocaleLowerCase()")}}</li>
<li>{{jsxref("String.prototype.toLocaleUpperCase()")}}</li>
<li>{{jsxref("String.prototype.toLowerCase()")}}</li>
</ul>
|