Open In App
Related Articles

JavaScript String toUpperCase() Method

Improve Article
Improve
Save Article
Save
Like Article
Like

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




function func() {
    let str = 'geeksforgeeks';
    let string = str.toUpperCase();
    console.log(string);
}
func();


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
function func() {
 
    // Original string
    let str = 'It iS a 5r&:ampe@@t Day.'
 
    // String converted to Upper Case
    let string = str.toUpperCase();
    console.log(string);
}
 
func();


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' ]

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

Supported Browser:

  • Chrome 1 and above
  • Edge 12 and above
  • Firefox 1 and above
  • Internet Explorer 3 and above
  • Opera 3 and above
  • Safari 1 and above

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


Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks 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!

Last Updated : 29 Nov, 2023
Like Article
Save Article
Previous
Next
Similar Reads
Complete Tutorials