I volontari di MDN non hanno ancora tradotto questo articolo in Italiano. Unisciti a noi e traducilo tu stesso.
Puoi anche consultare l’articolo in English (US).
The toUpperCase() method returns the calling string value converted to uppercase (the value will be converted to a string if it isn't one).
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
Syntax
str.toUpperCase()
Return value
A new string representing the calling string converted to upper case.
Exceptions
TypeError- When called on
nullorundefined, for example,String.prototype.toUpperCase.call(undefined).
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
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:
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);
Specifications
| Specification | Status | Comment |
|---|---|---|
| ECMAScript 1st Edition (ECMA-262) | Standard | Initial definition. Implemented in JavaScript 1.0. |
| ECMAScript 5.1 (ECMA-262) The definition of 'String.prototype.toUpperCase' in that specification. |
Standard | |
| ECMAScript 2015 (6th Edition, ECMA-262) The definition of 'String.prototype.toUpperCase' in that specification. |
Standard | |
| ECMAScript Latest Draft (ECMA-262) The definition of 'String.prototype.toUpperCase' in that specification. |
Draft |
Browser compatibility
| Desktop | Mobile | Server | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
toUpperCase | Chrome Full support Yes | Edge Full support 12 | Firefox Full support 1 | IE Full support Yes | Opera Full support Yes | Safari Full support Yes | WebView Android Full support Yes | Chrome Android Full support Yes | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support Yes | nodejs Full support Yes |
Legend
- Full support
- Full support