-
Notifications
You must be signed in to change notification settings - Fork 22.4k
/
index.md
72 lines (47 loc) · 1.43 KB
/
index.md
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
---
title: String.prototype.toUpperCase()
slug: Web/JavaScript/Reference/Global_Objects/String/toUpperCase
page-type: javascript-instance-method
browser-compat: javascript.builtins.String.toUpperCase
---
{{JSRef}}
The **`toUpperCase()`** method of {{jsxref("String")}} values returns this string converted to uppercase.
{{EmbedInteractiveExample("pages/js/string-touppercase.html", "shorter")}}
## Syntax
```js-nolint
toUpperCase()
```
### Parameters
None.
### Return value
A new string representing the calling string converted to upper case.
## Description
The `toUpperCase()` method returns the value of the string converted to
uppercase. This method does not affect the value of the string itself since JavaScript
strings are immutable.
## Examples
### Basic usage
```js
console.log("alphabet".toUpperCase()); // 'ALPHABET'
```
### Conversion of non-string `this` values to strings
This method will convert any non-string value to a string, when you set its
`this` to a value that is not a string:
```js
const a = String.prototype.toUpperCase.call({
toString() {
return "abcdef";
},
});
const b = String.prototype.toUpperCase.call(true);
// prints out 'ABCDEF TRUE'.
console.log(a, b);
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{jsxref("String.prototype.toLocaleLowerCase()")}}
- {{jsxref("String.prototype.toLocaleUpperCase()")}}
- {{jsxref("String.prototype.toLowerCase()")}}