JavaScript String.toLocaleUpperCase() Method
-
Syntax of JavaScript
string.toLocaleUpperCase()
: -
Example Codes: Use the
String.toLocaleUpperCase()
Method to Convert the Characters to Uppercase -
Example Codes: Use the
string.toLocaleUpperCase()
Method to Specify a Language Tag as alocale
Parameter
The string.toLocaleUpperCase()
method converts the lowercase characters of a given string into uppercase based on the specified locale case mappings. By default, the method will use the current locale of the host.
For most languages, there is no need to add a parameter in the toLocaleUpperCase()
method.
Syntax of JavaScript string.toLocaleUpperCase()
:
refString.toLocaleUpperCase();
refString.toLocaleUpperCase(locale);
Parameter
locale |
To specify a locale using language tags to convert the lowercase characters of a string into uppercase. |
Return
It returns a new string that includes all the characters of a string in uppercase based on particular locale case mappings.
Example Codes: Use the String.toLocaleUpperCase()
Method to Convert the Characters to Uppercase
The string.toLocaleUpperCase()
method converts a string in lowercase characters into uppercase. Some languages might require a locale
parameter in the string.toLocaleUpperCase()
method to convert lowercase into uppercase characters.
To check the output, we have passed the string.toLocaleUpperCase()
method without any parameter in the following example.
let string = 'café';
let upStr = string.toLocaleUpperCase();
console.log(upStr);
Output:
CAFÉ
Example Codes: Use the string.toLocaleUpperCase()
Method to Specify a Language Tag as a locale
Parameter
The websites and applications run on different hosts and browsers. Using the BCF 47 language tags as a parameter in the string.toLocaleUpperCase()
method, we can ensure that the string containing lowercase characters is accurately converted into uppercase.
We have passed a language tag as a locale
parameter in the example below.
var string = 'select français or español language.';
let frStr = string.toLocaleUpperCase('fr-FR');
console.log(frStr);
Output:
SELECT FRANÇAIS OR ESPAÑOL LANGUAGE.
The string.toLocaleUpperCase()
method converts a string containing local language characters into uppercase based on the specific locale case mappings. Since, by default, this method uses the host’s current locale, we add language tags as a parameter.
The .toUpperCase()
method gives similar results; however, the toLocaleUpperCase()
method converts locale languages with accuracy.