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 RepresentationExample 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 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()
Krunal Lathiya is a seasoned Computer Science expert with over eight years in the tech industry. He boasts deep knowledge in Data Science and Machine Learning. Versed in Python, JavaScript, PHP, R, and Golang. Skilled in frameworks like Angular and React and platforms such as Node.js. His expertise spans both front-end and back-end development. His proficiency in the Python language stands as a testament to his versatility and commitment to the craft.