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.
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
.
In JavaScript, if no arguments are provided to the toLocaleUpperCase()
method, it converts the string to uppercase according to the current locale.
For example,
str
with the value 'hello'
.toLocaleUpperCase()
method with no arguments.newStr
.newStr
to the console using the console.log()
method.const str = 'hello';
const newStr = str.toLocaleUpperCase();
console.log(newStr);
HELLO
In JavaScript, we can use the toLocaleUpperCase()
method with a specified locale to convert the string to uppercase.
For example,
str
with the value 'istanbul'
.toLocaleUpperCase()
method with the argument 'tr'
for Turkish locale.newStr
.newStr
to the console using the console.log()
method.const str = 'istanbul';
const newStr = str.toLocaleUpperCase('tr');
console.log(newStr);
İSTANBUL
In JavaScript, we can specify multiple locales to the toLocaleUpperCase()
method to ensure proper case conversion for multiple languages.
For example,
str
with the value 'hello'
.toLocaleUpperCase()
method with the arguments 'en-US'
and 'tr'
.newStr
.newStr
to the console using the console.log()
method.const str = 'hello';
const newStr = str.toLocaleUpperCase(['en-US', 'tr']);
console.log(newStr);
HELLO
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.