transformation
String.prototype.toUpperCase
Returns a new string with all characters converted to upper case using the Unicode default case mapping. Locale-insensitive — use toLocaleUpperCase for language-specific rules (e.g. Turkish i).
str.toUpperCase() Parameters
| Parameter | Purpose |
|---|---|
| (no arguments) | Method takes no parameters |
| returns | New upper-cased string (original unchanged) |
Examples
console.log('hello'.toUpperCase()); Prints 'HELLO'
console.log('Straße'.toUpperCase()); Prints 'STRASSE'
console.log('abc123'.toUpperCase()); Prints 'ABC123'
const s = 'hi'; s.toUpperCase(); console.log(s); Prints 'hi' (original unchanged; strings immutable)
Gotcha
Not locale-aware — Turkish 'i' becomes 'I' instead of 'İ'. Some characters expand (ß to SS), so length can change.
Related methods
String.prototype.toLowerCase
Returns a new string with all characters converted to lower case using Unicode default case mapping. For locale-specific behavior use toLocaleLowerCase.
String.prototype.normalize
Returns the Unicode Normalization Form of the string ('NFC', 'NFD', 'NFKC', or 'NFKD'; default 'NFC'). Essential for reliable comparison of characters that can be represented in multiple code point sequences.
String.prototype.localeCompare
Returns a negative number, 0, or a positive number indicating whether the string sorts before, equal to, or after compareString according to the current or supplied locale. Preferred over < and > for user-visible sorting.
String.prototype.replace
Returns a new string with the first match of pattern replaced. Pattern can be a string (only the first occurrence) or a RegExp (all occurrences when the g flag is set).
String.prototype.replaceAll
Returns a new string with every occurrence of pattern replaced. Added in ES2021; if pattern is a RegExp it must have the g flag or replaceAll throws TypeError.