Skip to content
Related Articles

Related Articles

JavaScript String toUpperCase() Method

View Discussion
Improve Article
Save Article
  • Last Updated : 23 Dec, 2021
View Discussion
Improve Article
Save Article

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

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!