JavaScript String toLocaleUpperCase() Method

JavaScript String toLocaleUpperCase() method is used to convert a string to uppercase letters based on the current locale. The locale is based on the language settings of the browser. This method does not modify the original string.

Syntax

string.toLocaleUpperCase([locale]);

Parameters

locale: It is an optional argument and suggests a locale to convert to the upper case according to any locale-specific case mappings if multiple locales are given in an Array.

Return value

It returns a new string converted to uppercase according to the current locale.

Visual RepresentationVisual Representation of JavaScript String toLocaleUpperCase() MethodExample 1: How to Use String toLocaleUpperCase() Method

let text = 'AppDividend';
upperText = text.toLocaleUpperCase()
console.log(upperText);

Output

APPDIVIDEND

In the above example, the output is ‘APPDIVIDEND’, which is the uppercase version of ‘AppDividend‘. Since toLocaleUpperCase() is used without a locale argument, it defaults to the user’s current locale.

Example 2: Multiple localesVisual Representation of Multiple locales

let text = 'Boß'; // German letter 'ß'
console.log('EN-US: ' + text.toLocaleUpperCase('en-US')); 
console.log('TR: ' + text.toLocaleUpperCase('tr'));
console.log('De: ' + text.toLocaleUpperCase('de-DE'));

Output

EN-US: BOSS
TR: BOSS
De: BOSS

In this example, we used the German lowercase letter ‘ß‘, which is typically converted to ‘SS‘ in most locales. Therefore, the output for ‘en-US‘, ‘tr‘, and ‘de-DE‘ locales is ‘BOSS‘.

Browser compatibility

  • Google Chrome 1
  • Edge 12
  • Firefox 1
  • Opera 4
  • Safari 1.3

Related posts

JavaScript String toLowerCase()

JavaScript String toLocaleLowerCase()

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.