String.prototype.toUpperCase()

toUpperCase()
Returns: string · Added in vES1 · Updated March 13, 2026 · String Methods
string case uppercase

The toUpperCase() method returns the string converted to uppercase. This is useful for case normalization, constants naming, and text formatting.

Syntax

str.toUpperCase()

Parameters

toUpperCase() takes no parameters.

Examples

Basic usage

const str = "hello world";
console.log(str.toUpperCase()); // "HELLO WORLD"

const mixed = "JaVaScRiPt";
console.log(mixed.toUpperCase()); // "JAVASCRIPT"

Constants and enum values

const status = "active";
const constantStatus = status.toUpperCase();
console.log(constantStatus); // "ACTIVE"

const statuses = {
  ACTIVE: "active",
  INACTIVE: "inactive",
  PENDING: "pending"
};

function getStatusKey(value) {
  return Object.keys(statuses).find(
    key => statuses[key] === value
  )?.toUpperCase();
}

Acronym extraction

function toAcronym(text) {
  return text
    .split(/\s+/)
    .map(word => word.charAt(0).toUpperCase())
    .join('');
}

console.log(toAcronym("javaScript")); // "JS"
console.log(toAcronym("world wide web")); // "WWW"

Locale-aware conversion

For specific locales, use toLocaleUpperCase():

const str = "istanbul";

console.log(str.toUpperCase()); // "ISTANBUL"
console.log(str.toLocaleUpperCase('tr')); // "İSTANBUL" (Turkish dotted İ)
console.log(str.toLocaleUpperCase('en')); // "ISTANBUL"

Unicode behavior

// Works with accented characters
console.log("çöşğü".toUpperCase()); // "ÇÖŞĞÜ"

// Works with Greek letters  
console.log("σ".toUpperCase()); // "Σ"

Common Patterns

Combine with trim for input normalization

function normalizeInput(input) {
  return input.trim().toUpperCase();
}

console.log(normalizeInput("  hello  ")); // "HELLO"
console.log(normalizeInput("  world  ")); // "WORLD"

Create constant-style identifiers

function toConstantName(str) {
  return str
    .replace(/\s+/g, '_')
    .toUpperCase();
}

console.log(toConstantName("max value")); // "MAX_VALUE"
console.log(toConstantName("api key")); // "API_KEY"

Sort strings case-insensitively (uppercase)

const fruits = ["Banana", "apple", "Cherry", "date"];
fruits.sort((a, b) => a.toUpperCase().localeCompare(b.toUpperCase()));
console.log(fruits);
// ["apple", "Banana", "Cherry", "date"]

Key Behaviors

  • Does not modify the original string—returns a new one
  • Only affects letters; numbers and symbols remain unchanged
  • Works for all Unicode characters, including accented letters
  • Locale-sensitive versions exist: toLocaleUpperCase()

See Also