The Wayback Machine - https://web.archive.org/web/20250102133429/https://www.geeksforgeeks.org/javascript-string-touppercase-method/
Open In App

JavaScript String toUpperCase() Method

Last Updated : 16 Sep, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

JavaScript String toUpperCase() method converts the entire string to Upper case.

This method does not affect any of the special characters, digits, and the alphabets that are already in the upper case. 

Syntax:

str.toUpperCase()

Parameters:

This method does not accept any parameter.

Return value:

This method returns a new string in which all the lowercase letters are converted to uppercase.

Example 1: In this example, we are converting the given string to uppercase.

JavaScript
let str = 'geeksforgeeks';
let string = str.toUpperCase();
console.log(string);

Output
GEEKSFORGEEKS

Example 2: In this example, the method toUpperCase() converts all the lower case alphabets to their upper case equivalents without affecting the special characters and the digits. 

JavaScript
// JavaScript String toUpperCase() method
// to convert string to Uppercase

// Original string
let str = 'It iS a 5r&:ampe@@t Day.'

// String converted to Upper Case
let string = str.toUpperCase();

console.log(string);

Output
IT IS A 5R&:AMPE@@T DAY.

Example 3: In this example, we are creating an array of data with elements ‘javascript’, ‘html’, and ‘css’. It uses map() and toUpperCase() to convert each element to uppercase.

JavaScript
let data = [ 'javascript', 'html', 'css' ];

let result = data.map(data => data.toUpperCase());

console.log(result);

Output
[ 'JAVASCRIPT', 'HTML', 'CSS' ]

Supported Browsers:

  • Chrome 1
  • Edge 12
  • Firefox 1
  • Opera 3
  • Safari 1

JavaScript String toUpperCase() Method – FAQs

How does the toUpperCase() method work?

The toUpperCase() method processes each character in the string and converts it to its uppercase equivalent if it has one. The method returns a new string with all characters in uppercase.

How does the toUpperCase() method handle non-alphabetic characters?

The toUpperCase() method does not change non-alphabetic characters such as numbers, punctuation, and special characters. These characters remain the same in the returned string.

Does the toUpperCase() method modify the original string?

No, the toUpperCase() method does not modify the original string. It returns a new string with the characters converted to uppercase.

Can the toUpperCase() method be used on strings with mixed case?

Yes, the toUpperCase() method can be used on strings with mixed case. It converts all lowercase alphabetic characters to uppercase while leaving non-alphabetic characters unchanged.

What are some common use cases for the toUpperCase() method?

Common use cases for the toUpperCase() method include:

  • Converting user input to uppercase for consistent formatting and comparison.
  • Normalizing strings for case-insensitive searching and matching.
  • Ensuring consistent display of text in user interfaces.
  • Standardizing data before storage or processing.

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

JavaScript is best known for web page development but it is also used in a variety of non-browser environments. You can learn JavaScript from the ground up by following this JavaScript


Next Article

Similar Reads

three90RightbarBannerImg