JavaScript Case Conversion and Locale Sensitivity
Quick answer
Case conversion maps text to uppercase or lowercase. Unicode case mappings can change the number of code units and may depend on locale.
How it works
toUpperCase and toLowerCase apply default Unicode casing; toLocaleUpperCase and toLocaleLowerCase accept locale tags. In Turkish the letter I has special casing. localeCompare returns a negative, positive or zero result for ordering, not guaranteed -1 or 1. For human-facing comparisons prefer an explicitly configured locale and options.
console.log("straße".toUpperCase(), "HELLO".toLowerCase());Expected output in Node.js:
STRASSE helloThe sharp s expands to two uppercase letters.
console.log("I".toLocaleLowerCase("tr"), "I".toLowerCase());Expected output in Node.js:
ı iThe Turkish locale uses dotless i; default conversion uses i.
Common mistakes
Lowercasing is not a complete Unicode case-folding or identity policy. Do not assume equal string lengths after conversion.
Practice
Compare the casing of I under the Turkish and default mappings.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
JavaScript Case Conversion and Locale Sensitivity — Knowledge Check
Apply the taught concept and predict the output.
Which method accepts a locale for lowercasing?
How should a localeCompare result be tested for an earlier sort position?
Can a Unicode uppercase conversion increase string length?
What is the exact console output in JavaScript Case Conversion and Locale Sensitivity example 1?
console.log("straße".toUpperCase(), "HELLO".toLowerCase());What is the exact console output in JavaScript Case Conversion and Locale Sensitivity example 2?
console.log("I".toLocaleLowerCase("tr"), "I".toLowerCase());