JavaScript Reference Β· String
String.prototype.toUpperCase()
Reference for JavaScript String.prototype.toUpperCase(): convert a string to upper case with Unicode rules, capitalize words, and learn about length changes.
The toUpperCase() method returns a copy of a string with its letters converted to upper case. Digits, punctuation and characters that have no upper-case form stay unchanged.
You use it for display (headings, labels), for comparing text ignoring case, and as part of capitalizing words. It follows the Unicode default mappings and ignores the user's locale; see toLocaleUpperCase() for language-specific rules.
"quiet".toUpperCase(); // "QUIET"
Try it
Press Run (or Ctrl + Enter) to see the console output here.
No output.
Press Run (or Ctrl + Enter) to see the console output here.
No output.
Syntax
string.toUpperCase()
This method takes no parameters.
Return value: a new string in which each character is converted to upper case according to the Unicode default mappings.
Exceptions: none for strings. Calling it on null or undefined throws a TypeError.
Usage notes
- Immutable: the original string is not modified; strings never are.
- Length may grow. The German
ΓbecomesSS, and some ligatures expand into several letters, so do not assume the result has the same length or that indexes line up. - Round trips are lossy.
"straΓe".toUpperCase().toLowerCase()gives"strasse", not the original. - Capitalizing a word needs more than this method. A common pattern is
text[0].toUpperCase() + text.slice(1), buttext[0]isundefinedfor an empty string, so calling a method on it throws;charAt(0)returns an empty string and is safe. - Code points beyond the first unit:
charAt(0)takes one UTF-16 code unit, so an initial character outside the Basic Multilingual Plane (for example in some alphabets) would be split. UseArray.from(text)orcodePointAt()there. - Not locale-aware: in Turkish,
"i"should become"Δ°"; usetoLocaleUpperCase("tr"). - CSS alternative: if you only want the text to look upper case,
text-transform: uppercaseleaves the data unchanged and respects thelangattribute. - Comparison: to compare ignoring case, convert both sides the same way, or use
Intl.Collatorwith asensitivityoption for user-facing text.
Browser support
String.prototype.toUpperCase() is supported in every browser.