JavaScript String toLocaleUpperCase() is a built-in method that returns a new string where all the characters are converted to uppercase according to the current locale’s rules. This method is beneficial when dealing with language-specific case mappings not covered by the regular toUpperCase() method.
Syntax
string.toLocaleUpperCase([locale]);
Parameters
The locale parameter is optional and indicates a locale to convert to the upper case according to any locale-specific case mappings if multiple locales are given in an Array.
Example
let data = 'brōkən';
console.log(data.toLocaleUpperCase('en-US'));
Output
The toLocaleUpperCase() method returns a value of the string converted to the upper case according to any locale-specific case mappings.
The toLocaleUpperCase() does not affect the value of a string itself. In most cases, it will produce the same outcome as toUpperCase(), but for some locales, such as Turkish, whose case mappings do not follow default case mappings in the Unicode, there may be a different outcome.
Also, notice that conversion is not necessarily the 1:1 character mapping, as some characters might result in two or even more characters when transformed to the upper case.
Therefore the length of the result string can differ from an input length. Unfortunately, this also implies that the conversion is not stable; for example, the following code can return the false:
x.toLocaleLowerCase() === x.toLocaleUpperCase().toLocaleLowerCase()
See the following examples.
console.log('appdividend'.toLocaleUpperCase());
console.log('appäß'.toLocaleUpperCase());
console.log('i\u0307'.toLocaleUpperCase('lt-LT'));
let locales = ['lt', 'LT', 'lt-LT', 'lt-u-co-phonebk', 'lt-x-lietuva'];
console.log('i\u0307'.toLocaleUpperCase(locales));
Output
That’s it for this tutorial.