Skip to content
  • (+91) 9409548155
  • support@appdividend.com
  • Home
  • Pricing
  • Instructor
  • Tutorials
    • Laravel
    • Python
    • React
    • Javascript
    • Angular
  • Become A Tutor
  • About Us
  • Contact Us
Menu
  • Home
  • Pricing
  • Instructor
  • Tutorials
    • Laravel
    • Python
    • React
    • Javascript
    • Angular
  • Become A Tutor
  • About Us
  • Contact Us
  • Home
  • Pricing
  • Instructor
  • Tutorials
    • Laravel
    • Python
    • React
    • Javascript
    • Angular
  • Become A Tutor
  • About Us
  • Contact Us
JavaScript

JavaScript String toUpperCase() Method

  • 08 Aug, 2025
  • Com 0
String toUpperCase() Method in JS

JavaScript String toUpperCase() method converts a string to uppercase letters and returns a new string with all characters in uppercase. It does not change the original string.

It can handle Unicode characters, including those outside the ASCII range.

Converting an input string to uppercase using JavaScript

let str = 'Cristiano Ronaldo is a Portuguese professional footballer';

upperStr = str.toUpperCase();

console.log(upperStr);

// Output: CRISTIANO RONALDO IS A PORTUGUESE PROFESSIONAL FOOTBALLER

Syntax

string.toUpperCase()

Parameters

None: It accepts no arguments.

Using special characters and digits

Using special characters and digits

The toUpperCase() method only affects alphabetic characters. Digits and special characters remain unchanged.

let str = 'Cristiano Ron@ldo CR7';

upperStr = str.toUpperCase();

console.log(upperStr);

// Output: CRISTIANO RON@LDO CR7

Converting only the first letter of a string

Converting only the first letter of a string

To convert the first letter of a string to uppercase, you can use the “charAt()” method together with “toUpperCase()” and then concatenate this with the rest of the string using “slice()”.

let str = "cristiano ronaldo";

str = str.charAt(0).toUpperCase() + str.slice(1);

console.log(str);

// Output: Cristiano ronaldo

Converting the First Letter of Every Word in a String

Converting the First Letter of Every Word in a String

To convert the first letter of every word in a string to uppercase, you can split the string into words, converting the first letter of each word to uppercase, and then joining the words back together.

let str = "cristiano ronaldo";

str = str.split(' ')
  .map(word => word.charAt(0).toUpperCase() + word.slice(1))
  .join(' ');

console.log(str);

// Output: Cristiano Ronaldo

Unicode characters

Converting Unicode characters to uppercase in JavaScriptIf the input string contains non-ASCII characters, the method handles correctly and does not throw any error. 

Let’s use a German word and convert it into uppercase correctly.

const unicode_str = "straße"; // German "street"

console.log(unicode_str.toUpperCase());

// Output: "STRASSE"

Locale-Specific behavior

Locale-Specific behavior in string.toUpperCase() function

What if you want to translate words based on the specific locale? For example, let’s translate the word into the Turkish specific locale. Can we achieve that through string.toUpperCase()? Well, no, for that, we need to use the string.toLocaleUpperCase(‘tr-TR’) method.

Let me show you the difference between these two methods:

turkish_str = 'istanbul'

// Turkish 'i' without locale handling  
console.log(turkish_str.toUpperCase());

// Output: 'ISTANBUL' (standard)  

// Using locale-sensitive method  
console.log(turkish_str.toLocaleUpperCase('tr-TR'));

// Output: 'İSTANBUL'

You can see the clear difference between “I” and “İ”. Both are different characters, and the second one is based on the locale translation, which is what we want.

Empty string

When you apply the toUpperCase() method to an empty string, it returns an empty string.

const empty = "";

console.log(empty.toUpperCase());

// Output: ""

Non-String input

If you pass non-string input, it will throw: TypeError: obj.toUpperCase is not a function error.

const num = 123;

console.log(num.toUpperCase());

// Output: TypeError: num.toUpperCase is not a function

It is better to check if the input is a string before applying the method to prevent this type of error.

Null or Undefined

It throws a TypeError if you call it on null or undefined.

try {
   console.log(null.toUpperCase());
} catch (e) {
   console.log(e.message);
   // Output: Cannot read properties of null (reading 'toUpperCase')
}

That’s all!

Post Views: 34
Share on:
Krunal Lathiya

With a career spanning over eight years in the field of Computer Science, Krunal’s expertise is rooted in a solid foundation of hands-on experience, complemented by a continuous pursuit of knowledge.

How to Use Pi in Python
JavaScript String toLowerCase() Method

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Address: TwinStar, South Block – 1202, 150 Ft Ring Road, Nr. Nana Mauva Circle, Rajkot(360005), Gujarat, India

Call: (+91) 9409548155

Email: support@appdividend.com

Online Platform

  • Pricing
  • Instructors
  • FAQ
  • Refund Policy
  • Support

Links

  • About Us
  • Contact Us
  • Privacy Policy
  • Terms of services

Tutorials

  • Angular
  • React
  • Python
  • Laravel
  • Javascript
Copyright @2024 AppDividend. All Rights Reserved
Appdividend