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:

1.
toLocaleUpperCase()

This method converts the characters within the string to uppercase according to the current locale.

Returns value of type String.

2.
toLocaleUpperCase(locales)

Parameters

ParameterOptional/RequiredDescription
localesoptionalA 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,

  1. We define a string variable str with the value 'hello'.
  2. We use the toLocaleUpperCase() method with no arguments.
  3. The result is stored in the variable newStr.
  4. We log newStr to the console using the console.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,

  1. We define a string variable str with the value 'istanbul'.
  2. We use the toLocaleUpperCase() method with the argument 'tr' for Turkish locale.
  3. The result is stored in the variable newStr.
  4. We log newStr to the console using the console.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,

  1. We define a string variable str with the value 'hello'.
  2. We use the toLocaleUpperCase() method with the arguments 'en-US' and 'tr'.
  3. The result is stored in the variable newStr.
  4. We log newStr to the console using the console.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.