String.prototype.toUpperCase()
The toUpperCase()
method returns the calling string value
converted to uppercase (the value will be converted to a string if it isn't one).
Syntax
toUpperCase()
Return value
A new string representing the calling string converted to upper case.
Exceptions
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 |
---|
ECMAScript Language Specification # sec-string.prototype.touppercase |
Browser compatibility
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
toUpperCase | ChromeFull support1 | EdgeFull support12 | FirefoxFull support1 | Internet ExplorerFull support3 | OperaFull support3 | SafariFull support1 | WebView AndroidFull support1 | Chrome AndroidFull support18 | Firefox for AndroidFull support4 | Opera AndroidFull support10.1 | Safari on iOSFull support1 | Samsung InternetFull support1.0 | DenoFull support1.0 | Node.jsFull support0.10.0 |
Legend
- 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.