JavaScript String toLocaleUpperCase()
Syntax & Examples
String.toLocaleUpperCase() method
The toLocaleUpperCase() method of the String class in JavaScript converts the characters within a string to uppercase while respecting the current locale or the specified locale.
Syntax of String.toLocaleUpperCase()
There are 2 variations for the syntax of String.toLocaleUpperCase() method. They are:
toLocaleUpperCase()This method converts the characters within the string to uppercase according to the current locale.
Returns value of type String.
toLocaleUpperCase(locales)Parameters
| Parameter | Optional/Required | Description |
|---|---|---|
locales | optional | A string with a BCP 47 language tag, or an array of such strings. This affects the locale to be used during the conversion. |
This method converts the characters within the string to uppercase according to the specified locale.
Returns value of type String.
✐ Examples
1 Using toLocaleUpperCase() method with no arguments
In JavaScript, if no arguments are provided to the toLocaleUpperCase() method, it converts the string to uppercase according to the current locale.
For example,
- We define a string variable
strwith the value'hello'. - We use the
toLocaleUpperCase()method with no arguments. - The result is stored in the variable
newStr. - We log
newStrto the console using theconsole.log()method.
JavaScript Program
const str = 'hello';
const newStr = str.toLocaleUpperCase();
console.log(newStr);Output
HELLO
2 Using toLocaleUpperCase() method with a single locale argument
In JavaScript, we can use the toLocaleUpperCase() method with a specified locale to convert the string to uppercase.
For example,
- We define a string variable
strwith the value'istanbul'. - We use the
toLocaleUpperCase()method with the argument'tr'for Turkish locale. - The result is stored in the variable
newStr. - We log
newStrto the console using theconsole.log()method.
JavaScript Program
const str = 'istanbul';
const newStr = str.toLocaleUpperCase('tr');
console.log(newStr);Output
İSTANBUL
3 Using toLocaleUpperCase() method with multiple locale arguments
In JavaScript, we can specify multiple locales to the toLocaleUpperCase() method to ensure proper case conversion for multiple languages.
For example,
- We define a string variable
strwith the value'hello'. - We use the
toLocaleUpperCase()method with the arguments'en-US'and'tr'. - The result is stored in the variable
newStr. - We log
newStrto the console using theconsole.log()method.
JavaScript Program
const str = 'hello';
const newStr = str.toLocaleUpperCase(['en-US', 'tr']);
console.log(newStr);Output
HELLO
Summary
In this JavaScript tutorial, we learned about toLocaleUpperCase() method of String: the syntax and few working examples with output and detailed explanation for each example.