This JavaScript tutorial explains how to use the string technique called toLocaleUpperCase() with syntax and examples.
Description
In JavaScript, toLocaleUpperCase() is a string approach that is used to convert a string to uppercase based totally on locale. Because the toLocaleUpperCase() approach is a method of the String object, it need to be invoked via a specific instance of the String class.
Syntax
In JavaScript, the syntax for the toLocaleUpperCase() approach is:
string.toLocaleUpperCase([locale]);
Parameters or Arguments
locale Optional. It is a BCP forty seven language tag or an array of such tags. A BCP 47 language tag defines a language that may additionally comprise a foremost language code as nicely as an extension. If this parameter is not provided, the toLocaleUpperCase() approach will use the host environment’s current locale.
Returns
The toLocaleUpperCase() approach returns a string converted to uppercase the use of a unique locale.
Note
The toLocaleUpperCase() technique does now not alternate the fee of the authentic string.
Example
Let’s take a seem at an instance of how to use the toLocaleUpperCase() approach in JavaScript.
For example:
var totn_string = 'TechOnTheNet';
console.log(totn_string.toLocaleUpperCase());
In this example, we have declared a variable called totn_string that is assigned the string value of ‘TechOnTheNet’. We have then invoked the toLocaleUpperCase() approach of the totn_string variable to convert the string to uppercase.
We have written the output of the toLocaleUpperCase() technique to the internet browser console log, for demonstration purposes, to show what the toLocaleUpperCase() method returns.
The following will be output to the web browser console log:
TECHONTHENET
In this example, the toLocaleUpperCase() approach used the host’s cutting-edge locale and converted the string ‘TechOnTheNet’ to uppercase and lower back a string fee of ‘TECHONTHENET’.
Specifying a Locale Parameter
Instead of using the host’s modern locale, you can also specify a BCP forty seven language tag for the locale parameter that will be used to convert the string to uppercase.
For example:
var totn_string = 'café';
console.log(totn_string.toLocaleUpperCase('en-US'));
The following will be output to the internet browser console log:
CAFÉ
In this example, the toLocaleUpperCase() approach used a locale parameter of ‘en-US’ to convert the string to uppercase using US English. The toLocaleUpperCase() method back a string value of ‘CAFÉ’.
Leave a Review