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.
Errors thrown
A TypeError
will be thrown if you call this method on null
or undefined
(via Function.prototype.call
, for example).
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);
Calling on undefined
and null
// TypeError String.prototype.toUpperCase.call(undefined);
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
The compatibility table in 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.
Desktop | Mobile | Server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Basic support | Chrome Full support Yes | Edge Full support Yes | 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 | Edge Mobile 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