String.prototype.toUpperCase()
The mirror of toLowerCase, with one extra hazard: upper-casing can change the length of the string, which no amount of index arithmetic will survive.
Demo
The German ß is the case to look at: it upper-cases to two characters, SS, so 'straße' becomes seven letters from six. Any code that assumed a case conversion preserves length — a fixed-width field, an index calculated before the call — is wrong for this input. The Greek case is a second example of a many-to-one mapping: both the regular sigma and the word-final sigma ς map to the same capital Σ, so upper-casing Greek text is not reversible either.
Common patterns
const cc = input.trim().toUpperCase();
const title = s.charAt(0).toUpperCase() + s.slice(1);
text-transform: uppercase;
Examples
Pitfalls
'stra\u00dfe'.length + ' -> ' + 'stra\u00dfe'.toUpperCase().length
const upper = s.toUpperCase(); const n = upper.length;
'\u00df'.toUpperCase().toLowerCase()
const display = original; const key = original.toLowerCase();
let s = 'abc'; s.toUpperCase(); s
let s = 'abc'; s = s.toUpperCase(); s
input.value = input.value.toUpperCase()
text-transform: uppercase
When to use
- Normalising codes that are conventionally upper case — currency, country, state
- Capitalising a single leading character
- Matching a protocol that specifies upper case
- Shouting for visual effect → text-transform in CSS
- Case-insensitive comparison → toLowerCase is the conventional direction
- Text the user reads → toLocaleUpperCase with their locale
- You rely on the length staying the same → it does not
Notes
FAQ
Because there was no capital ß in standard German orthography when the Unicode mappings were written, so the defined upper-case form of ß is the two-letter SS. A capital ẞ was later encoded, but the default mapping was not changed — it would break existing text.
'stra\u00dfe'.toUpperCase(); // 'STRASSE'