CodePark/ questions / Unicode & text
START PRACTICINGPRACTICE
Frontend question · Internationalization › Unicode & text

What do these two lines print?

console.log("title".toUpperCase());
console.log("title".toLocaleUpperCase("tr-TR"));
TITLE and TİTLE

Turkish has a dotted and a dotless "i". The uppercase of a dotted "i" is "İ", with a dot. The lowercase of "I" is a dotless "ı". toUpperCase() uses the language-neutral rules, but toLocaleUpperCase("tr-TR") uses the Turkish ones.

"
TITLE twice" is the tempting wrong answer. Case rules depend on the language, and some change the length, like German "straße", which uppercases to "STRASSE". Use the locale versions for text you display. For case-insensitive comparison, use Intl.Collator with sensitivity: "base" instead of uppercasing both strings.