Skip to content
Related Articles

Related Articles

JavaScript String toUpperCase() Method
  • Last Updated : 01 Sep, 2020

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

  • Example:




    <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:




<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:




<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.

full-stack-img

My Personal Notes arrow_drop_up
Recommended Articles
Page :