• JavaScript Video Tutorials

JavaScript String toLocaleUpperCase() Method



The JavaScript String toLocaleUpperCase() method in JavaScript returns a new string by converting the original string into uppercase letters using any locale-specific based on the language settings of the browser you are using. It does not modify the original string.

The toLocaleUpperCase() method in JavaScript returns the same result as the touppercase() method. The only difference is that the toLocaleUpperCase() method takes a locale as an optional parameter, whereas the touppercase() method does not.

Syntax

Following is the syntax of JavaScript String toLocaleUpperCase() method −

toLocaleUpperCase(locales)

Parameters

  • locales − The locale to be used to convert string to uppercase.

Return value

This method return a new string by converting them into uppercase using the specified locales.

Example 1

If we omit the locale parameter, this method simply converts the given strings into uppercase letters without using any locales, as it has not been specified.

<html>
<head>
<title>JavaScript String toLocaleUpperCase() Method</title>
</head>
<body>
<script>
   const str = "tutorials point";
   document.write("Original string: ", str);
   document.write("<br>New string(uppercase): ", str.toLocaleUpperCase());
</script>    
</body>
</html>

Output

The above program returns a new string as "TUTORIALS POINT".

Original string: tutorials point
New string(uppercase): TUTORIALS POINT

Example 2

The following is another example of the JavaScript String toLocaleUpperCase() method. In this example, we use this method to convert a given string "Hello World" into uppercase using the locale "EN-US".

<html>
<head>
<title>JavaScript String toLocaleUpperCase() Method</title>
</head>
<body>
<script>
   const str = "Hello World";
   const locale = "EN-US";
   document.write("Original string: ", str);
   document.write("<br>The locale is: ", locale);
   document.write("<br>New string(uppercase): ", str.toLocaleUpperCase(locale));
</script>    
</body>
</html>

Output

After executing the above program, it will return a new string as "HELLO WORLD".

Original string: Hello World
The locale is: EN-US
New string(uppercase): HELLO WORLD
Advertisements