References

Beginner-friendly references for web development, with live, editable examples.

The JavaScript string.toUpperCase() method

Method JavaScript All modern browsers Updated
Quick answer

The toUpperCase() method returns a new string with every letter converted to uppercase. "hello".toUpperCase() gives "HELLO". With its partner toLowerCase(), it's the standard way to compare strings without caring about case. The original string is never changed.

Overview

toUpperCase() capitalizes every letter in a string and returns the result as a new string. Non-letters are left as they are, and the original is untouched, since strings can't be changed in place.

Beyond obvious display jobs — shouting a heading, formatting a country code — its quiet workhorse role is case-insensitive comparison. To check if two strings match regardless of case, convert both the same way first: a.toLowerCase() === b.toLowerCase(). Most code reaches for toLowerCase() for this, but either works as long as you're consistent.

A small caveat for international text: a few characters don't have a simple one-to-one uppercase form, and locale can matter (the Turkish dotless "i" is the classic example). For those cases there's toLocaleUpperCase(). For everyday English text, toUpperCase() is all you need.

Syntax

const upper = str.toUpperCase()

"hello".toUpperCase()  // "HELLO"

Example

Live example
<pre id="out" style="font:15px ui-monospace,monospace"></pre>
<script>
  const code = 'us';
  const name = 'javascript';

  const capitalized = name.charAt(0).toUpperCase() + name.slice(1);

  document.getElementById('out').textContent =
    code.toUpperCase() + '\n' + capitalized; // US / Javascript
</script>

Best practices

  • Use the return value — strings are immutable, so the original is unchanged.
  • For case-insensitive comparison, convert both strings the same way first.
  • Use toLocaleUpperCase() when locale-specific rules matter (e.g. Turkish).
  • To capitalize just the first letter, combine slice() with toUpperCase() on the first character.

Frequently asked questions

How do I convert a string to uppercase in JavaScript?
Call str.toUpperCase(). It returns a new all-caps string.
Does toUpperCase() change the original string?
No. It returns a new string; the original is unchanged because strings are immutable.
How do I compare two strings ignoring case?
Convert both with the same method first: a.toLowerCase() === b.toLowerCase().
How do I capitalize only the first letter?
Combine the pieces: s.charAt(0).toUpperCase() + s.slice(1).