Skip to content
Tutorials Center
My learning

Topics

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.

JavaScript
"quiet".toUpperCase(); // "QUIET"

Try it

JS Upper-casing and capitalizing

Press Run (or Ctrl + Enter) to see the console output here.

No output.

JS The length can change

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Syntax

JavaScript
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 ß becomes SS, 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), but text[0] is undefined for 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. Use Array.from(text) or codePointAt() there.
  • Not locale-aware: in Turkish, "i" should become "Δ°"; use toLocaleUpperCase("tr").
  • CSS alternative: if you only want the text to look upper case, text-transform: uppercase leaves the data unchanged and respects the lang attribute.
  • Comparison: to compare ignoring case, convert both sides the same way, or use Intl.Collator with a sensitivity option for user-facing text.

Browser support

String.prototype.toUpperCase() is supported in every browser.