Javascript String ToLocaleUpperCase() Tutorial With Example

Javascript String ToLocaleUpperCase() Tutorial With Example

Javascript String ToLocaleUpperCase() Tutorial With Example is today’s topic. In the JavaScript language, the toLocaleUpperCase() method is the string method that is used to convert the string into the uppercase based on locale. Because the toLocaleUpperCase() method is the method of a String object, it must be invoked through the particular instance of the String class. We have already covered a Javascript toLocaleLowerCase().

Javascript String ToLocaleUpperCase() Tutorial

In JavaScript, the syntax for the toLocaleUpperCase() method is following.

string.toLocaleUpperCase([locale]);

The locale parameter is optional and indicates a locale to be used to convert to the upper case according to any locale-specific case mappings if the multiple locales are given in an Array.

See the following code example.

// app.js

let data = 'brōkən';
console.log(data.toLocaleUpperCase('en-US'));

See the following output.

Javascript String ToLocaleUpperCase() Tutorial

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 the most cases, it will produce the same outcome as toUpperCase(), but for some locales, such as the Turkish, whose case mappings do not follow a 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 of the characters might result in the two or even more characters when transformed to the upper-case. Therefore a length of the result string can differ from an input length. 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 more examples.

// app.js

console.log('appdividend'.toLocaleUpperCase());

console.log('appäß'.toLocaleUpperCase());

console.log('iu0307'.toLocaleUpperCase('lt-LT'));

let locales = ['lt', 'LT', 'lt-LT', 'lt-u-co-phonebk', 'lt-x-lietuva'];
console.log('iu0307'.toLocaleUpperCase(locales));

See the following output.

String ToLocaleUpperCase() Tutorial With Example

Finally, Javascript String ToLocaleUpperCase() Tutorial With Example is over.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *