Thursday, July 4, 2024
HomeLanguagesJavascriptJavaScript String toLocaleUpperCase() Method

JavaScript String toLocaleUpperCase() Method

The String.prototype.toLocaleUpperCase() method in JavaScript is a Standard built-in object which returns the calling string value converted to the uppercase letter on the basis of the host’s current locale. This method mostly returns a similar result as the string toUppercase() method

Syntax:

str.toLocaleUpperCase()
str.toLocaleUpperCase(locale)

Parameters:

  • locale: It is an optional parameter and this locale parameter indicates the locale to be used to convert to upper case according to any locale-specific case mappings.

Returns Value:

This method returns a string of uppercase letters. 

Exceptions:

This method gives two kinds of errors, which are as follows:

  • RangeError: If the locale argument isn’t a valid language tag.
  • TypeError: If an array element isn’t of type string.

The below examples illustrate the String.prototype.toLocaleUpperCase() method in JavaScript: 

Example 1: In this example, we will convert some lowercase strings into uppercase letters using the String.prototype.toLocaleUpperCase() method in JavaScript.

javascript




// Input string
let gfg = 'GeeKsForGeekS';
 
// Display output with upper case
console.log('EN-US: ' + gfg.toLocaleUpperCase('en-US'));
console.log('TR: ' + gfg.toLocaleUpperCase('tr'));
 
// New input string
let gfg1 = new String("String.prototype.toLocaleUpperCase()");
 
// Display output with upper case
console.log('Result: ' + gfg1.toLocaleUpperCase());


Output

EN-US: GEEKSFORGEEKS
TR: GEEKSFORGEEKS
Result: STRING.PROTOTYPE.TOLOCALEUPPERCASE()

Example 2: In this example, we will convert some lowercase strings into uppercase letters using the String.prototype.toLocaleUpperCase() method in JavaScript.

javascript




console.log('ALPHABET'.toLocaleUpperCase());
 
console.log('i\u0307'.toLocaleUpperCase('tr') === 'I');
console.log('i\u0307'.toLocaleUpperCase('lt-LT') === 'I');
 
let neveropen = ['lt', 'LT', 'lt-LT', 'lt-u-co-phonebk', 'lt-x-lietuva'];
console.log('i\u0307'.toLocaleUpperCase(neveropen) === 'I');


Output

ALPHABET
false
true
true

We have a complete list of Javascript String methods, to check those please go through this JavaScript String Complete Reference article.

Supported Browsers: The browsers supported by the String.prototype.toLocaleUpperCase() method are listed below:

  • Google Chrome
  • Firefox
  • IE
  • Opera
  • Safari
  • Edge

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

Nokonwaba Nkukhwana
Experience as a skilled Java developer and proven expertise in using tools and technical developments to drive improvements throughout a entire software development life cycle. I have extensive industry and full life cycle experience in a java based environment, along with exceptional analytical, design and problem solving capabilities combined with excellent communication skills and ability to work alongside teams to define and refine new functionality. Currently working in springboot projects(microservices). Considering the fact that change is good, I am always keen to new challenges and growth to sharpen my skills.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments