Skip to content
Related Articles

Related Articles

Improve Article

JavaScript String toUpperCase() Method

  • Last Updated : 07 Oct, 2021
Geek Week

Below is the example of the String toUpperCase() Method. 
 

  • Example: 
     

JavaScript




<script>
function func() {
    var str = 'geeksforgeeks';
    var string = str.toUpperCase();
    document.write(string);
}
func();
</script>
  • Output: 
     
GEEKSFORGEEKS

str.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()

Return value: 
This method returns a new string in which all the lower case letters are converted to upper case.
Examples for the above method are provided below:
Example 1: 
 

var str = 'It iS a Great Day.';
var string = str.toUpperCase();
print(string);

Output: 
 

IT IS A GREAT DAY.

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. 
Example 2: 
 



var str = 'It iS a 5r&e@@t Day.'
var string = str.toUpperCase();
print(string);

Output: 
 

IT IS A 5R&AMP;E@@T DAY.

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. 
Codes for the above method are provided below:
Program 1:
 

JavaScript




<script>
// JavaScript to illustrate .toUpperCase()
 
function func() {
     
    // Original string
    var str = 'It iS a Great Day.';
     
    // String converted to Upper Case
    var string = str.toUpperCase();
    document.write(string);
}
 
func();
</script>

Output: 
 

IT IS A GREAT DAY.

Program 2:
 

JavaScript




<script>
// JavaScript to illustrate .toUpperCase()
function func() {
     
    //Original string
    var str = 'It iS a 5r&:ampe@@t Day.'
     
    //String converted to Upper Case
    var string = str.toUpperCase();
    document.write(string);
}
 
func();
</script>

Output: 
 

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

 

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

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it’s lowest price ever!




My Personal Notes arrow_drop_up
Recommended Articles
Page :