Skip to content
Related Articles

Related Articles

Which built-in method returns the calling string value converted to upper case in JavaScript ?

Improve Article
Save Article
Like Article
  • Difficulty Level : Easy
  • Last Updated : 31 Dec, 2021

The toUpperCase() built-in method returns the calling string value converted to uppercase in the javascript. This method does not affect any of the special characters, digits, and alphabets that are already in the upper case. 

Syntax:

String.prototype.toUpperCase()

Approach: This is a simple HTML file. In the body, there are two p tags one with id text in which some content is written and then there is a button with which a function is associated and it will be called on event onclick with the mouse. Inside the script tag, there is some js code, in the first line we are extracting the string from the p tag with id ‘text’ and later inside the function clickHandler() which will eventually be called when someone will click on the associated button. This function contains a call to the toUpperCase() method by the string named myString. In the end, we are simply putting the result into the p tag with id text.

Example:

HTML




<!DOCTYPE html>
<html>
  
<body>
  
    <p>
        The text written below will be converted
        to Upper Case after clicking on Button
    </p>
  
    <p id="text">Hello, GeeksforGeeks Learner!!</p>
  
    <button onclick="clickHandler()">
        Click Here
    </button>
      
    <script>
        let myString = document.getElementById("text").innerHTML;
          
        const clickHandler = () => {
            let result = myString.toUpperCase();
            document.getElementById("text").innerHTML = result;
        }
    </script>
</body>
  
</html>

Output:

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!