String. prototype. toUpperCase()
Returns a copy of the string converted to uppercase. Handles accented letters correctly.
- Returns
- A new string with the letters converted to uppercase.
- Changes the original
- No
Example
#const city = 'zürich'
const code = 'promo2026'
console.log(city.toUpperCase())
console.log(code.toUpperCase())
console.log(city)Definition and usage
#The toUpperCase() method returns a new string in which every letter is uppercase. Digits, spaces, and punctuation stay unchanged, and accented letters, such as é, ñ, or ü, are converted correctly. The method takes no arguments.
It is most often used to compare text regardless of letter case (you bring both sides to the same form), to format codes and headings, and, combined with slice(), to capitalize the first letter of a word.
The result can have a different length than the original: the German ß turns into SS. For languages with special rules, such as Turkish, use toLocaleUpperCase("tr"). The original string stays unchanged.
Syntax
#string.toUpperCase()More examples
#const correct = 'JavaScript'
const answer = 'javascript'
console.log(answer === correct)
console.log(answer.toUpperCase() === correct.toUpperCase())const name = 'chloé'
const formatted = name.charAt(0).toUpperCase() + name.slice(1)
console.log(formatted)console.log('straße'.toUpperCase())
console.log('istanbul'.toUpperCase())
console.log('istanbul'.toLocaleUpperCase('tr'))Browser support
#Widely available
Works in all modern browsers, phones included. You can use it without worry.
- Chrome
- Edge
- Firefox
- Safari
Good practices
#- For case-insensitive comparisons, you can also use
localeCompare()with the{ sensitivity: "base" }option. It also ignores accents, such aséande, though exactly which letters are still treated as distinct can depend on the locale you pass in. - If the text only needs to look like it is written in uppercase, consider
text-transform: uppercasein CSS instead. The data then stays in its original form.
Related entries
#- String.prototype.toLowerCase()Returns a copy of the string converted to lowercase. Useful for comparisons and normalizing data.
- String.prototype.localeCompare()Compares two strings according to language rules. Returns a negative number, zero, or a positive number, perfect for sorting.
- String.prototype.charAt()Returns the character at the given index. Outside the valid range, it returns an empty string instead of undefined.
- String.prototype.slice()Returns a portion of a string from a start index to an end index (not included). Supports negative indexes.
Spotted a mistake or missing an example? Write to us.