JavaScriptStrings

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
On this page

Example

#
JavaScript
const city = 'zürich'
const code = 'promo2026'

console.log(city.toUpperCase())
console.log(code.toUpperCase())
console.log(city)
Console
ZÜRICH
PROMO2026
zürich

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

#
Syntax
string.toUpperCase()

More examples

#
Comparing regardless of letter case
JavaScript
const correct = 'JavaScript'
const answer = 'javascript'

console.log(answer === correct)
console.log(answer.toUpperCase() === correct.toUpperCase())
Console
false
true
Capitalizing the first letter
JavaScript
const name = 'chloé'
const formatted = name.charAt(0).toUpperCase() + name.slice(1)

console.log(formatted)
Console
Chloé
Length changes and language-specific rules
JavaScript
console.log('straße'.toUpperCase())
console.log('istanbul'.toUpperCase())
console.log('istanbul'.toLocaleUpperCase('tr'))
Console
STRASSE
ISTANBUL
İSTANBUL

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 é and e, 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: uppercase in CSS instead. The data then stays in its original form.

Related entries

#

Spotted a mistake or missing an example? Write to us.